declare @SQLString nvarchar(500),@shopStr nvarchar(50)set @SQLString =N'declare cur_shop cursor for
select shopid from shop where shopstatus=''A'' order by ' + @shopStr
exec sp_executesql @SQLString
open cur_shop ......
select shopid from shop where shopstatus=''A'' order by ' + @shopStr
exec sp_executesql @SQLString
open cur_shop ......
select shopid from shop where shopstatus=''A'' order by ' + @shopStr
exec sp_executesql @SQLString
open cur_shop ......
for select shopid from shop where shopstatus=''A'' order by '+@shopStr )这样看看
for select shopid from shop where shopstatus=''A'' order by '+@shopStr )这样看看
declare @SQLString nvarchar(500),@shopStr nvarchar(50)set @SQLString =N'declare cur_shop cursor for
select shopid from shop where shopstatus=''A'' order by ' + @shopStr
exec sp_executesql @SQLString
open cur_shop ......
for select shopid from shop where shopstatus=''A'' order by '+@shopStr )这样看看
declare @SQLString nvarchar(500),@shopStr nvarchar(50)set @SQLString =N'declare cur_shop cursor for
select shopid from shop where shopstatus=''A'' order by ' + @shopStr
exec sp_executesql @SQLString
open cur_shop ......
for select shopid from shop where shopstatus=''A'' order by '+@shopStr )
Declare cur_shop Cursor
for select shopid from tmp ..drop table tmp
DECLARE @id varchar(50)
set @id= 'id'
exec('select top 20 * from table1 order by '+@id +' desc')
是可以的.CURSOR 的作用域是默认全局的.
当然跟Database的选项设置有关系.
报错如下名为 'cur_shop' 的游标不存在。
因为你没有给@shopStr 赋值,与@SQLString 相加后@SQLString 也变成NULL了,当然就没游标啦
exec(' select shopid into tmp from shop where shopstatus=''A'' order by '+ @shopStr )
Declare cur_shop Cursor
for select shopid from tmp
open cur_shop错误如下:
...
'by' 附近有语法错误。
对象名 'tmp' 无效。
...
谁有测试过的sql正确语句,快贴出来...
Declare cur_shop Cursor
for select shopid from tmp
open cur_shop