DECLARE cur cursor FOR SELECT xx FROM tb; OPEN curDECLARE @xx intFETCT NEXT FROM cur INTO @xx;WHILE @@FETCH_STATUS=0 BEGIN EXEC usp_name @xx; FETCT NEXT FROM cur INTO @xx; ENDCLOSE cur; DEALLOCATE cur;
--用游标 declare @str varchar(100), @str1 varchar(100) --定义游标 declare DZCursor CURSOR for SELECT col1,col2 FROM test where test_str='xxx' open DZCursor fetch next from DZCursor into @str,@str1 while @@fetch_status=0 begin --执行你的存储过程语句 fetch next from DZCursor into @str ,@str1 end --关闭游标 close DZCursor --删除游标 deallocate DZCursor
很好很强大 --用游标 declare @str varchar(100), @str1 varchar(100) --定义游标 declare DZCursor CURSOR for SELECT col1,col2 FROM test where test_str='xxx' open DZCursor fetch next from DZCursor into @str,@str1 while @@fetch_status=0 begin --执行你的存储过程语句 fetch next from DZCursor into @str ,@str1 end --关闭游标 close DZCursor --删除游标 deallocate DZCursor
declare @tb table (id int,name varchar(10)) declare c_k cursor select * from 表 open c_k fetch from c_k into @tb while @@FETCH_STATUS=0 begin exec '' fetch from c_k into @tb end close c_k deallocate c_k
用动态语句declare @sql varchar(8000) set @sql='' select @sql=' exec 存储过程 ' + 参数属性 from tb
SELECT xx FROM tb;
OPEN curDECLARE @xx intFETCT NEXT FROM cur INTO @xx;WHILE @@FETCH_STATUS=0
BEGIN
EXEC usp_name @xx;
FETCT NEXT FROM cur INTO @xx;
ENDCLOSE cur;
DEALLOCATE cur;
declare @str varchar(100), @str1 varchar(100)
--定义游标
declare DZCursor CURSOR for SELECT col1,col2 FROM test where test_str='xxx'
open DZCursor
fetch next from DZCursor into @str,@str1
while @@fetch_status=0
begin
--执行你的存储过程语句
fetch next from DZCursor into @str ,@str1
end
--关闭游标
close DZCursor
--删除游标
deallocate DZCursor
--用游标
declare @str varchar(100), @str1 varchar(100)
--定义游标
declare DZCursor CURSOR for SELECT col1,col2 FROM test where test_str='xxx'
open DZCursor
fetch next from DZCursor into @str,@str1
while @@fetch_status=0
begin
--执行你的存储过程语句
fetch next from DZCursor into @str ,@str1
end
--关闭游标
close DZCursor
--删除游标
deallocate DZCursor
declare @tb table (id int,name varchar(10))
declare c_k cursor select * from 表
open c_k
fetch from c_k into @tb
while @@FETCH_STATUS=0
begin
exec ''
fetch from c_k into @tb
end
close c_k
deallocate c_k
set @sql=''
select @sql=' exec 存储过程 ' + 参数属性 from tb
到这里看看有没有你的解决方案,这里搜集了大乌龟,诌老大等大牛们的很多sql语句