在我的存儲過程中有一個輸入參數
根據該參數的不同值,我要更新同一個表的不同字段,我想用CASE實現,請問如何做。
謝謝
1 樓ldy(羅大佑)回覆於 2002-06-11 17:00:13 得分 10
update l_sent
set if_print = if_print + 1,
serial =
case isnull(serial,0)
when 0 then :ll_serial
else serial
end
where mine_code = :gs_mine and sent_sdate = :ls_date and car_num = :ls_car;
commit;Top
2 樓ldy(羅大佑)回覆於 2002-06-11 17:01:30 得分 0
update l_sent
set if_print = if_print + 1,
serial =
case isnull(serial,0)
when 0 then :ll_serial
else serial
end
where mine_code = :gs_mine and sent_sdate = :ls_date and car_num = :ls_car;
commit;Top
3 樓ldy(羅大佑)回覆於 2002-06-11 17:02:28 得分 0
update l_sent
set if_print = if_print + 1,
serial =
case isnull(serial,0)
when 0 then :ll_serial
else serial
end
where mine_code = :gs_mine and sent_sdate = :ls_date and car_num = :ls_car;
commit;Top
4 樓qybao(阿寶)回覆於 2002-06-11 17:07:39 得分 0
不同字段,用if吧
If @參數 = 值1
Update table1
Set Field1 = value1
Where ...
Else if @參數 = 值2
Update table1
Set Field2 = value2
Where ...
Else
...Top
5 樓tj_dns(愉快的登山者)回覆於 2002-06-11 17:11:38 得分 10
使用動態SQL
select @item = (case @para when '1' then 'item1' when '2' then 'item2' else 'itemn' end)
set @sql = 'update tablename set '+@item+' = @value'
exec(@sql)Top
6 樓zhangxdd(xudong)回覆於 2002-06-14 23:03:44 得分 0
謝謝羅大佑和愉快的登山者,
你們的方法都可實現,