Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Update parameterized query question

Author  Topic 

DaveBF
Yak Posting Veteran

89 Posts

Posted - 2011-02-22 : 08:47:16
I have a parameterized Update query, and in certain cases, I want to leave a column as it was. So for example, if I have
Update mytable Set Amount=@Amount, Name=@Name where myID=@ID

is there a way to say don't change the Amount?

Thanks,
Dave

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-02-22 : 08:49:42
you can pass in NULL to @Amount and use COALESCE() t

UPDATE mytable SET Amount = COALESCE(@Amount, Amount)
. . .


EDIT : typo err


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

DaveBF
Yak Posting Veteran

89 Posts

Posted - 2011-02-23 : 11:17:44
Thank you!
Go to Top of Page
   

- Advertisement -