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

Popular posts from this blog

c# - SelectList with Dictionary, add values to the Dictionary after it's assigned to SelectList -

how can i manage url using .htaccess in php? -

ios - I get the error Property '...' not found on object of type '...' -