sql - Can I check if a variable is NULL within an Update's SET? -


i have stored procedure uses simple update variables passed it. don't want update fields when variables aren't null. statement looks like.

update mytable set mycolumn = @mycolumn,     mcolumn1 = @mycolumn1 mycolumn2 = @mycolumn2 

is there anyway apply conditional logic within set? have around 10 fields need checked, wouldn't want update per field or that.

any ideas?

coalesce friend. returns first non-null argument. i'm not sure narrative way around want things, it's either:

update mytable set mycolumn = coalesce(mycolumn,@mycolumn),     mcolumn1 = coalesce(mycolumn1,@mycolumn1) mycolumn2 = @mycolumn2 

which keeps current column's value if column's not null, or

update mytable set mycolumn = coalesce(@mycolumn,mycolumn),     mcolumn1 = coalesce(@mycolumn1,mycolumn1) mycolumn2 = @mycolumn2 

which keeps current column's value if variable null.


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -