Hi all,
I am currently using a cursor to in which to LOOP around a result set and whilst within the LOOP I would like run another query where I need to store the result into a varaible. I have tried the following but that just throws errors at me
I heard its bad to use a cursor within another cursor, so will not attempt this.Code:@testvar = (SELECT upc_pk FROM lupc_pts_contract WHERE lupc_code = @contrcode)
Is there anyway I can get the result from this query into a variable?
My overall code looks like this...
TrystCode:-- DECLARE VARIABLES HERE DECLARE c1 CURSOR FOR (SELECT id, plan_date, contract, cancout FROM meridian.dbo.planpatients WHERE LEN(cancout) > 0) OPEN c1 FETCH NEXT FROM c1 INTO @var1, @var2, @var4, @var3 WHILE @@FETCH_STATUS = 0 BEGIN -- GET NEW CONTRACT CODE @testvar = (SELECT upc_pk FROM lupc_pts_contract WHERE lupc_code = @contrcode) -- PERFORM CODE EXECUTION HERE!! FETCH NEXT FROM c1 INTO @var1, @var2, @var4, @var3 END CLOSE c1 DEALLOCATE c1






Bookmarks