SQL set variable to a value in the current row
sql, t-sql
Solution
You probably want to do something like this, depending on how you're generating rowID:
SELECT @agentID = agentID FROM agentTable WHERE @index = rowID;
And then continue on your merry way with whatever it is your logic needs to do.
Problem
What I am trying to do is perform a loop that goes through each column in my table and sets the variable @agent to that column's agentID. Here is the code I have so far: ``` Declare @index int = 1 Declare @agentCount = Max(rowID) Declare @agentID int While(@i =< @agentCount) Begin If(@index = rowID) Begin --Set @agentID (to current row's agentID) Exec mergeagentLogRecords @agentID, @startDate, @endDate End Set @index = @index + 1 End ``` I hope I explained myself well enough :P Thanks for looking!