经常写存储过程,但今天在游标使用过程中还是疏忽了一些事情,执行过程中一直执行不下去,后来直接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='…
1.简单游标 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 declare m_cursor cursor scroll for select Address,PeopleId from PeopleDetail open m_cursor declare @Address varchar(50), @PeopleId int fetch next from m_cursor into @Address,@PeopleId while @@FETCH_S…
工作中用到的记录一下,游标的详细定义及说明请百度 --游标格式化数据 DECLARE cursor_jxsmb CURSOR FOR --定义一个游标 SELECT F0 FROM dbo.JXSMB2019; --定于游标的数据源 OPEN cursor_jxsmb --打开游标 DECLARE @LAST NVARCHAR(4000),@THIS NVARCHAR(4000) --定义两个变量,用来保存上一行和当前行的数据 FETCH NEXT FROM cursor_jxsmb INTO…
---游标更新删除当前数据 ---1.声明游标 declare orderNum_03_cursor cursor scroll for select OrderId ,userId from bigorder where orderNum='ZEORD003402' --2.打开游标 open orderNum_03_cursor --3.声明游标提取数据所要存放的变量 ) --4.定位游标到哪一行 fetch First from orderNum_03_cursor into @Order…
declare @id int ) declare c_department cursor for select id,name from department open c_department fetch next from c_department into @id,@name begin --代码 --代码 fetch next from c_department into @id,@name end close c_department deallocate c_department…
use [ElephantCredit] go begin transaction tran_bank; print '**脚本开始执行!'; declare @tran_error int , @negRuleId uniqueidentifier ; set @negRuleId = (select Id from [ElephantCredit].[dbo].[CreditRules] where [Provider]=N'CREDIT_PROVIDER_OPS' and [Code]=N…
通过嵌套,根据表中记录的表名与列名到指定位置取值. --声明存储过程 ProPIMS if (exists (select * from sys.objects where name = 'ProPIMS')) drop proc ProPIMS go create procedure ProPIMS ),) AS BEGIN ),),),),),@Columncount int; if exists(select * from tempdb..sysobjects where id=objec…
DECLARE @ProName NVARCHAR(50)DECLARE @CityName NVARCHAR(50)DECLARE @ProId INT DECLARE @CityId INT DECLARE Test_Cursor CURSOR LOCAL READ_ONLY STATIC FORWARD_ONLY FORSELECT a.AreaId,a.AreaName,b.AreaName FROM AreaFull AS a RIGHT JOIN AreaFull AS b ON a…
CLOSE orderNum_02_cursordeallocate orderNum_02_cursorDECLARE orderNum_02_cursor cursor SCROLL for select vcThemeId from LG_LiveTheme_OrderDECLARE @themeid varchar(10)OPEN orderNum_02_cursorfetch first from orderNum_02_cursor INTO @themeidWHILE @@FETC…