Home > Net >  what is blanket update in SQL query?
what is blanket update in SQL query?

Time:05-07

I have a few update queries, and I need them as a blanket update.

update Table_A  set status=0 where task_type='AAA' and task_name='BBB';

update Table_A set status=0 where task_type='CCC' and task_name='DDD';

update Table_A  set status=0 where task_type='EEE' and task_name='FFF';

I need this to be a blanket update

CodePudding user response:

It sounds like you need a single update that will cover all your scenarios - something like this

update Table_A  set status= 
    case 
        when task_type ='AAA' and task_name='BBB' then 0
        when  task_type='CCC' and task_name='DDD' then 0
        when task_type='EEE' and task_name='FFF' then 0
    end;

This works in MySQL, MSSQL, SQLite and PostgreSQL. I haven't tested it in Oracle

If you have other conditions then just extend the Case statement

CodePudding user response:

You can just combined all three where clauses with or

update Table_A  set status=0 
where (task_type='AAA' and task_name='BBB')
or (task_type='CCC' and task_name='DDD')
or (task_type='EEE' and task_name='FFF');
  •  Tags:  
  • sql
  • Related