1 用游标,循环多次调用存储过程 2 把存储过程改成函数,直接 select dbo.函数名(id) as result from t1 where id>100 你看哪个方便
declare @id int declare cur cursor for select id from t1 where id>100 open cur fetch next from cur into @id while @@fetch_status=0 begin exec sp_updateName @id,'testName' fetch next from cur into @id end close cur deallocate cur
create proc sp_updateName (@id int, @testName varchar(40)) as declare @T table(id int) insert @T select id from t1 where id>100 ...
效率要高的话.就在你存储过程实现sp_updateName .减少数据库循环处理.
请问: create proc sp_updateName (@id int, @testName varchar(40)) as declare @T table(id int) insert @T select id from t1 where id>100这种写法,后面如何来操作,我下面的操作,每次只能针对一个ID进行判断和操作的.
2 把存储过程改成函数,直接
select dbo.函数名(id) as result from t1 where id>100
你看哪个方便
declare cur cursor for select id from t1 where id>100
open cur
fetch next from cur into @id
while @@fetch_status=0
begin
exec sp_updateName @id,'testName'
fetch next from cur into @id
end
close cur
deallocate cur
as
declare @T table(id int)
insert @T select id from t1 where id>100
...
create proc sp_updateName (@id int, @testName varchar(40))
as
declare @T table(id int)
insert @T select id from t1 where id>100这种写法,后面如何来操作,我下面的操作,每次只能针对一个ID进行判断和操作的.