mssql 循环语句写法

  declare   @itemnumber   int   -- 定义需要循环的次数
 2  declare   @tagint   int   -- 定义标志字段,用于结束循环
 3  set   @tagint = 1
 4  select   @itemnumber   =   count ( distinct  Creater)  from  Demo_TestTable  where   isnull (Creater, '' ) <> ''   And  
   DATEDIFF ( DAY ,CreatDate, GETDATE ()) < 1
 5     if ( @itemnumber > 0 )
 6     begin
 7       while   @tagint <= @itemnumber
 8           begin
 9               waitfor  delay  ' 00:00:01 '   -- 每隔一秒再执行 可用参数变量替换
10               Update  Demo_TestTable  set  CreatDate = GETDATE ()  where  Creater  = (
11               Select  Creater  from  (
12                   select  Creater,ROW_NUMBER()  over ( order   by  Creater)  as  RowID  from  Demo_TestTable  where  
            isnull (Creater, '' ) <> ''   And   DATEDIFF ( DAY ,CreatDate, GETDATE ()) < 1   group   by  Creater
13               ) TableA
14                where   TableA.RowID = @tagint
15               )
16                set   @tagint = @tagint + 1
17           end
18     end
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值