我想为这多个查询创建单个查询

时间:2017-08-24 04:24:54

标签: sql

Update TransactionsMovs SET SubNumId='5253420' where SubNumId='3014362178619A000000033F' and CustNumKey='0024180002'
Update TransactionsMovs SET SubNumID='5253416' where SubNumId='301402662C2DC5800000017C' and CustNumKey='0024180003' 
Update TransactionsMovs SET SubNumID='5253419' where SubNumId='301402662C42F480000036AF' and CustNumKey='0024180004'
Update TransactionsMovs SET SubNumID='5253418' where SubNumId='30143639F809E880000003AA' and ItemNumKey='055270490-32-30'
Update TransactionsMovs SET SubNumID='5253417' where SubNumId='30140BA4EC4833C00000008C' and CustNumKey='0022870002' 

2 个答案:

答案 0 :(得分:1)

您想减少数据库往返吗? 如果是,您可以使用begin end包围查询;

BEGIN
    Update TransactionsMovs SET SubNumId='5253420' where SubNumId='3014362178619A000000033F' and CustNumKey='0024180002';
    Update TransactionsMovs SET SubNumID='5253416' where SubNumId='301402662C2DC5800000017C' and CustNumKey='0024180003';
    Update TransactionsMovs SET SubNumID='5253419' where SubNumId='301402662C42F480000036AF' and CustNumKey='0024180004';
    Update TransactionsMovs SET SubNumID='5253418' where SubNumId='30143639F809E880000003AA' and ItemNumKey='055270490-32-30';
    Update TransactionsMovs SET SubNumID='5253417' where SubNumId='30140BA4EC4833C00000008C' and CustNumKey='0022870002';
END;

答案 1 :(得分:0)

你正在尝试实现类似的功能,将所有条件与一个UPDATE语句组合在一起。

Update TransactionsMovs
SET    SubNumId = CASE WHEN SubNumId='3014362178619A000000033F' AND CustNumKey='0024180002' THEN '5253420' 
                       WHEN SubNumId='301402662C2DC5800000017C' AND CustNumKey='0024180003' THEN '5253416' 
                       WHEN SubNumId='301402662C42F480000036AF' AND CustNumKey='0024180004' THEN '5253419' 
                       WHEN SubNumId='30143639F809E880000003AA' AND ItemNumKey='055270490-32-30' THEN '5253418'
                       WHEN SubNumId='30140BA4EC4833C00000008C' AND CustNumKey='0022870002' THEN '5253417'         
          END