新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
SQL中類似For循環(huán)處理的實例
原本CreatDate的yyyy-MM-dd hh:mm:ss:fff格式被變成了yyyy-MM-dd格式,下面就將對SQL進(jìn)行類似For循環(huán)處理,該方法供您參考,希望對您學(xué)習(xí)SQL中的For循環(huán)能有所幫助。

- declare @itemnumber int --定義需要循環(huán)的次數(shù)
- declare @tagint int --定義標(biāo)志字段,用于結(jié)束循環(huán)
- 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' --每隔一秒再執(zhí)行 可用參數(shù)變量替換
- 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聚合函數(shù)之Avg 函數(shù)
SQL中MAX()和MIN()函數(shù)的使用
SQL中求和函數(shù)SUM()的應(yīng)用實例
TOP字句加SQL變量的相關(guān)問題
當(dāng)前文章:SQL中類似For循環(huán)處理的實例
分享網(wǎng)址:http://m.fisionsoft.com.cn/article/dpeoooo.html


咨詢
建站咨詢
