Hello, SQL 2008R2
I have a table that holds an QueueID and the number of accounts per agent.
I have a second table that holds accounts and QueueID into which I want to put an AgentID.
To do this, the stored procedure I am editing currently uses a cursor to loop through the first table to update the second.
How would I do this without the cursor? Or what sould I look up to help me?
Thank you,
djj
The Lord is my shepherd (Psalm 23) - I need someone to lead me!
I have a table that holds an QueueID and the number of accounts per agent.
I have a second table that holds accounts and QueueID into which I want to put an AgentID.
To do this, the stored procedure I am editing currently uses a cursor to loop through the first table to update the second.
Code:
DECLARE C1 CURSOR FOR
SELECT a.QueueID, a.AccountQty, qa.AgentID
FROM #TempAllocations a
INNER JOIN QueueAssignments qa
ON a.QueueID = qa.QueueID
WHERE a.AccountQty > 0
ORDER BY a.QueueID
OPEN C1
FETCH NEXT FROM C1 into @C1QueueDefnID, @C1AccountQty, @C1AgentID
--loop here ...
UPDATE T
SET NewAgentID = @C1AgentID
FROM #TempQBuild T
INNER JOIN (
SELECT TOP (@C1AccountQty) RefNum
FROM #TempQBuild
WHERE NewQueueDefnID = @C1QueueDefnID
AND NewAgentID = 91
ORDER BY NEWID() ) X
ON T.RefNum = X.RefNum
WHERE T.NewQueueDefnID = @C1QueueDefnID
Thank you,
djj
The Lord is my shepherd (Psalm 23) - I need someone to lead me!