1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| */ create procedure p_test as begin begin tran declare cur_test cursor for select id, name,dates from test where 1=1 declare @id int, @name varchar(50),@dates datetime open cur_test fetch next from cur_test into @id,@name,@dates while @@fetch_status<>-1 begin update test set name='x' where id=@id if @@error<>0 begin rollback tran end select *from test where id=@id if @@error<>0 begin rollback tran end fetch next from cur_test into @id,@name,@dates end close cur_test deallocate cur_test commit tran end --sp_helptext p_test
alter procedure p_test1 as begin begin tran declare cur_sa cursor for select id,name,thing,dates from test declare @id int,@name varchar(50),@thing varchar(50),@dates varchar(50) open cur_sa fetch next from cur_sa into @id,@name,@thing,@dates while @@fetch_status<>-1 begin select *from test where id=@id if @@error<>0 begin rollback tran end fetch next from cur_sa into @id,@name,@thing,@dates end close cur_sa deallocate cur_sa commit tran end
|