|
SET @sql = N'DECLARE cursor_problemrecord INSENSITIVE CURSOR FOR (SELECT grade, placeincomp, Year (bgndate) FROM problem_record WHERE recscid = 31 AND receid = @ eid AND (bgndate> = @ bgndate AND enddate <@enddate) '+ N' AND '+ @ otherwhere + N' ORDER BY bgndate DESC) '
EXEC sp_executesql @ sql, N '@ eid int, @ bgndate smalldatetime, @ enddate smalldatetime', @ eid, @ bgndate, @ enddate
The cursor is defined in a dynamic SQL statement, so the compilation here does not recognize it.
In the execution of dynamic SQL statements, the cursor is returned as a parameter.
(The cursor can only be passed out as a parameter in the stored procedure, not passed in)
EXEC sp_executesql @ sql, N '@ eid int, @ bgndate smalldatetime, @ enddate smalldatetime, cursor_problemrecord cursor output', @ eid, @ bgndate, @ enddate, cursor_problemrecord output
Try |
|