sp_executesql中使用游标

来源:互联网 发布:手机套淘宝网 编辑:程序博客网 时间:2024/06/10 01:23
set nocount ongoif object_id('test') is not null drop table testgocreate table test(id int identity(1,1) not null,name nvarchar(20))godeclare @count intselect @count=0;while @count<20begininsert into test values('name'+convert(varchar(20),@count));select @count=@count+1;endgo--测试游标declare @n varchar(500),@name nvarchar(20)set @n='n'exec sp_executesql N'declare cur cursor for select name from test where isnull(name,'''')<>'''' and name>@n',N'@n varchar(10)',@n;open curfetch next from cur into @namewhile @@fetch_status=0beginprint @namefetch next from cur into @name;endclose curdeallocate curgo

原创粉丝点击