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.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2003-04-15 : 07:43:57
|
| Matt writes "Can you use the exec command to run a prepared sql string and use it to open a cursor?delcare @sqlset @sql = 'Select * From Employee'declare #mycursor cursor scroll static read_only for exec(@sql)open #mycursor" |
|
|
dsdeming
479 Posts |
Posted - 2003-04-15 : 08:43:52
|
| You can try something like this ( running in Northwind ):DECLARE @sql varchar( 1000 ), @iEmployee intSET @sql = 'DECLARE #mycursor CURSOR SCROLL STATIC READ_ONLY FOR SELECT EmployeeID FROM Employees' EXEC(@sql) OPEN #mycursorFETCH NEXT FROM #mycursor INTO @iEmployeeWHILE @@FETCH_STATUS = 0BEGIN SELECT LastName, FirstName FROM Employees WHERE EmployeeID = @iEmployee FETCH NEXT FROM #mycursor INTO @iEmployeeENDCLOSE #mycursorDEALLOCATE #mycursor |
 |
|
|
|
|
|