Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cursor for a local variable

Status
Not open for further replies.

asmith555

Programmer
Oct 7, 2002
97
US
Can a cursor be declared for a SQL statement that resides in a local variable such as

"DECLARE curUsers CURSOR FOR @sSQL
 
Not unless you put all the cursor code in as dynamic SQL
i.e.
DECLARE @v_SQL VARCHAR(2000)
SET @v_SQL = 'DECLARE curUsers CURSOR FOR ' + @sSQL
SET @v_SQL = @v_SQL + 'Other code within cursor'
exec @v_Sql



"I'm living so far beyond my income that we may almost be said to be living apart
 
Insert results given by @sSQL into #temptable, then loop with cursor over it.

------
"There's a man... He's bald and wears a short-sleeved shirt, and somehow he's very important to me. I think his name is Homer."
(Jack O'Neill, Stargate)
[banghead]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top