2013年4月2日 星期二

[SQL] 一次更新多筆資料列 SqlServer2005 & SqlServer 2008

Table:


SQL:
            sqlQuery = "UPDATE [attend] SET " & _
            " hr = case type when '事假' then @hr事 " & _
            "when '病假' then @hr病 when '加班' then 0 when '遲到' then @hr遲 End, " & _
            " hrY = case type when '事假' then @hrY事 " & _
            "when '病假' then @hrY病 when '加班' then @hrY加 when '遲到' then 0 End, " & _
            " times = case type when '事假' then 0 " & _
            "when '病假' then 0 when '加班' then 0 when '遲到' then 0 End, " & _
            " timesY = case type when '事假' then 0 " & _
            "when '病假' then 0 when '加班' then @timesY加 when '遲到' then @timesY遲 End, " & _
            " times730 = case type when '事假' then 0 " & _
            "when '病假' then 0 when '加班' then @times730加 when '遲到' then 0 End, " & _
            "modifyDate=@ModifyDate,modifyUserName=@ModifyUserName," & _
            "modifyUserID=@ModifyUserID,SysModifyDate=@SystemModifyDate " & _
            "WHERE type in ('事假','病假','加班','遲到') AND ym = @ym AND staff_sn = @staff_sn;"

參考:
[SQL]INSERT & UPDATE multiple records
SQL 同一資料表中,大量更新?
如何一次更新同的欄位的多筆資料
一次更新多筆資料
一次新增多筆資料列 SqlServer2005 & SqlServer 2008
[SQL]將表格橫向呈現

沒有留言:

張貼留言