|
|
Question : parametized cursor declaration
|
|
is it possible to declare a parameterized cursor? if so, give a code example by modifying the example below (that doesn't work @Qsource,@start_time,@end_time are the variables).
DECLARE @Qcursor cursor SET @Qsource = @source + 'bas.dbo.QTab' DECLARE @Qcursor CURSOR for SELECT * from @Qsource where TEMPS >= ''@start_time'' AND TEMPS <= ''@end_time'' ORDER BY TEMPS FETCH NEXT FROM @Qcursor INTO @market, @time, @open, @close WHILE @@FETCH_STATUS = 0
|
Answer : parametized cursor declaration
|
|
DECLARE @Qcursor CURSOR for SELECT * from @Qsource where TEMPS >= @start_time AND TEMPS <= @end_time ORDER BY TEMPS
Be aware, though, that SQL (oddly) resolves the variables at *DECLARE* time, not at OPEN time. So if/when you change the values of the variables, you have to not only CLOSE and OPEN the cursor, but you must DEALLOCATE and re-DECLARE then open the cursor.
|
|
|
|
|