我有3个UPDATE
个语句(更新多个列),我想对一个id的列表执行,而不必对每个id
逐个运行3个更新语句.
以下是我需要对一堆id
运行的3个更新语句:
-- store ContractDate value in temp col
update tval set temp_col = (select val from tval where id = 402280209 and fid = 3782) where id = 402280209 and fid = 3782
-- Replace ContractDate with maturityDate
update tval set val= (select val from tval where fid = 3771 and id = 402280209) where fid = 3782 and id = 402280209
-- set MaturityDate to ContactDate
update tval set val = (select temp_col from tval where id = 402280209 and fid = 3782) where id = 402280209 and fid = 3771
我有一个id
的列表,我需要运行以上3更新语句对.是否可以将上述内容作为批处理(即在一个查询中)运行?
我的tval
表看起来像这样:
id fid ts val temp_col
402280209 3765 2021-09-20 00:00:00.000 2023-12-19 00:00:00.000
402280209 3771 2021-09-20 00:00:00.000 2023-09-20 00:00:00.000 <---- I would like to swap this value
402280209 3782 2021-09-20 00:00:00.000 2023-12-19 00:00:00.000 <----- with this value
我试图避免的是为每id
手动运行上面的操作.
所以我想要的结果是:
id fid ts val temp_col
402280209 3765 2021-09-20 00:00:00.000 2023-12-19 00:00:00.000
402280209 3771 2021-09-20 00:00:00.000 2023-12-19 00:00:00.000
402280209 3782 2021-09-20 00:00:00.000 2023-09-20 00:00:00.000