Blueimp 論壇首頁


列印 2024/4/20 上午 07:04:37

文章作者 jieh2007/3/20 下午 07:11:19
applause   動態欄位名稱更新 SQL
 
declare @vSQL nvarchar(500), @ColumnName varchar(50), @RunDate datetime, @DateStr char(8)

set @RunDate = '2007-12-25'

while @RunDate > '2006-02-01' begin

set @DateStr = convert(char(8), @RunDate, 112)
print @DateStr + ' 處理中......'

set @vSQL = 'update V2_繳款記錄 set last_in_date = ''' + @DateStr + ''''
+ ' from V2_繳款記錄 where income_' + convert(char(4), convert(int, substring(@DateStr, 1, 6)) - 191100)
+ ' = ''Y'' and last_in_date is null'

print @vSQL

execute sp_executesql @vSQL

set @RunDate = dateadd(month, -1, @RunDate)
continue end

轉貼時請加註來源引用自藍色小惡魔用 SQL 語法動態組合 SQL
http://www.imp.idv.tw/play/forum/viewthread?thread=743
<hr><script type="text/javascript" src="http://adcenter.conn.tw/oeya_ad.php?key=7967"></script>
就這樣... 原本要重貼 23 次的 SQL 就這樣取代掉了
SQL 的經典範例都很簡短 大家都是高手 自己玩自己摸應該沒問題 我就不廢話了
tongue

good luck

xuite, pixnet


2016/7/27:120
2016/7/27:328
----------------------------------------
支持小惡魔
BTC : 19tn3RnCuwZVukXAwyhDWZD4uBgUZoGJPx
LTC : LTFa17pSvvoe3aU5jbmfcmEpo1xuGa9XeA
知識跟八卦一樣,越多人知道越有價值;知識最好的備份方法,散播!
藍色小惡魔(林永傑): 臉書