原本CreatDate的yyyy-MM-dd hh:mm:ss:fff格式被变成了yyyy-MM-dd格式,下面就将对SQL进行类似For循环处理,该方法供您参考,希望对您学习SQL中的For循环能有所帮助。

- 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
 
【编辑推荐】
对存储过程代替SQL语句的讨论
SQL聚合函数之Avg 函数
SQL中MAX()和MIN()函数的使用
SQL中求和函数SUM()的应用实例
TOP字句加SQL变量的相关问题
                新闻名称:SQL中类似For循环处理的实例
                
                网站链接:http://www.csdahua.cn/qtweb/news14/436814.html
            
网站建设、网络推广公司-快上网,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 快上网