declare cro_fastread cursor scroll
for 后面跟参数可以吗`??
本来是:
declare cro_fastread cursor scroll
for select Pr_id from Product where tint_level=0 and [email protected]_tableid order by int_id desc
[email protected],[email protected]= "id=1 and name= 'aaa ' "
有人帮助下吗`> > ??
------解决方案--------------------
可以使用动态游标,因为游标可以使用EXEC()动态生成然后引用:
declare @sql varchar(8000),@x1 varchar(100)
----设置参数
set @x1 = 'id=1 and name= ' 'aaa ' ' '
----定义动态游标字符串
set @sql = '
declare cro_fastread cursor scroll
for select Pr_id from Product where tint_level=0 and [email protected]_tableid ' +
CASE WHEN isnull(@x1, ' ') = ' ' THEN ' ' ELSE ' and ' + @x1 END + [email protected]*/
' order by int_id desc '
----创建动态游标
EXEC(@sql)
----打开游标
open cro_fastread
fetch next from cro_fastread into ...
----循环游标
while @@fetch_status = 0
begin
...
fetch next from cro_fastread into ...
end
----关闭游标
close cro_fastread
----释放游标资源
deallocate cro_fastread