经常写存储过程,但今天在游标使用过程中还是疏忽了一些事情,执行过程中一直执行不下去,后来直接sqlserver挂了,教训啊! 代码虽简单,望铭记: Create PROCEDURE [dbo].[temphxb] AS BEGIN declare @uid int declare mycursortemp Cursor open mycursortemp fetch next from mycursortemp into @uid begin delete from temptable1 whe…
declare @temp_temp uniqueidentifier--临时变量 DECLARE aaa CURSOR for select Id from A -------------------打开游标 open aaa --先查询一次再循环,防止有多个游标时@@FETCH_STATUS=-1不能进入下个游标循环的情况 fetch next from aaa into @temp_temp -------------------循环取数据 while @@FETCH_STATUS=0 b…
游标实例: Declare MyCusror Cursor Scroll For Select * From Master_Goods Order By GoodsID Open MyCursor Fetch next From MyCursor Into @GoodsCode,@GoodsName While(@@Fetch_Status = 0) Begin Begin Select @GoodsCode = Convert(Char(2…
DECLARE ChangeInvCodeCursor CURSOR FOR SELECT A.name AS tablecolumn,C.name AS tablename FROM sys.columns A LEFT JOIN sys.types B ON A.user_type_id = B.user_type_id RIGHT JOIN SYS.tables C ON C.object_id=A.object_id WHERE A.name ='CINVCODE'OR A.name='…