Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 How can I define a cursor by using EXEC (@dynamicString)

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-09-17 : 20:13:30
Shane writes "I have a temp table that looks something like this:

RowID DBName sSQL
----- ------ -----------------------
1 db1 select sample1 from db1
2 db2 select sample2 from db2
3 db3 select sample3 from db3


The sSQL column can change at any given moment. I want to be able to step through each row of the temp table, execute the specific sSQL for that row, return that record set, create a second (nested) loop to step through each row of the record set.

I have tried the following approach (and have gone nowhere):

--This generates the record set, but won't capture into a
--temporary table, or cursor
select @tempsql = ssql from #temptable1 where rowid = @currentrow
exec (@tempsql)

I have also tried (and have gone nowhere):
select @tempsql = ssql from #temptable1 where rowid = @currentrow
--Poor cursor syntax
declare myCursor cursor for
exec (@tempsql)

This is defined as *.sql script file."
   

- Advertisement -