方法一:
不知道多输出参数如何写:
declare @cursor_name varchar(36),@str nvarchar(4000)
select @cursor_name=newid()
DECLARE @ckbm varchar(20)
exec('DECLARE ['+@cursor_name + '] CURSOR FOR select f_ckbm from tbda_ck')
exec('open ['+ @cursor_name+']')
set @str=N'fetch from ['+ @cursor_name +'] into @ckbm'
exec sp_executesql @str,N'@ckbm varchar(20) out',@ckbm out
while @@fetch_status = 0
begin
print @ckbm
exec sp_executesql @str,N'@ckbm varchar(20) out',@ckbm out
end
exec('close ['+ @cursor_name+']')
exec('deallocate ['+ @cursor_name+']')
|
方法二:
可以实现多输出参数
declare @sqlExec varchar(8000),@tableName varchar(255),@myvar varchar(20) set @tableName = 'Checkbag_info' set @sqlExec = 'declare cursor1 cursor for ' + CHAR(13) set @sqlExec = @sqlExec + ' select res_sort from ' + @tableName exec(@sqlExec) open cursor1 fetch next from cursor1 into @myvar while @@fetch_status = 0 begin print @myvar fetch next from cursor1 into @myvar end close cursor1 deallocate cursor1 |






