sql server 2008, need help to write conditional update statement -
i have simple update statment.
update tbabc set salary = 1000, name = 'mike' id = 1
i need add condition when update salary, if salary = 0, change 1000, otherwise salary not change.
i did research, , found similar question. using conditional update statement in sql
update tbabc set salary = case when (salary = 0) 1000 else ??????? end, name = 'mike' id = 1
i got stuck on ???? part. sure put there make salary = salary.
unless absolutely necessary, i'd prefer using clause rather complicated case function. simplifying, give:
update tbabc set salary=1000, name='mike' -- using condition both field updates id=1 , salary=0;
or preserving exact logic on transaction:
update tbabc set salary=1000 -- id & if second condition met id=1 , salary=0; update tbabc set name='mike' -- id. id=1;
i don't believe there's real-world case updating employee's name unconditionally, having condition on salary update.
Comments
Post a Comment