Question

I have this task where I need to assign a value if the value is null.

if its not null then I want to keep the value that is already there.. (this is what is stumping me) I know its got to be easy..

Thanks, Al

Was it helpful?

Solution

Coalesce() is what you should use, it's part of the ansi-99 standard as well.

Update [Table] Set
   Col1 = coalesce(Col1, @Col1Val)
  ,Col2 = coalesce(Col2, @Col2Val)
Where ...

OTHER TIPS

UPDATE myTable
  SET myCol = myDefaultValue
  WHERE myCol IS NULL;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top