DavidYun

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
 declare @itemnumber int --定义需要循环的次数
 declare @tagint int --定义标志字段,用于结束循环
 set @tagint=1
 select @itemnumber = count(distinct Creater) from Demo_TestTable where isnull(Creater,'')<>'' And 
   DATEDIFF(DAY,CreatDate,GETDATE())<1
   if(@itemnumber>0)
   begin
     while @tagint<=@itemnumber
         begin
             waitfor delay '00:00:01' --每隔一秒再执行 可用参数变量替换
             Update Demo_TestTable set CreatDate=GETDATE() where Creater =(
             Select Creater from (
                 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
              ) TableA
              where  TableA.RowID=@tagint
              )
              set @tagint=@tagint+1
         end
   end

 

posted on 2013-07-24 16:44  David.Yun  阅读(402)  评论(1编辑  收藏  举报