May 21, 2012 at 8:12 am
I have a table that looks like the following:

I want to be able to update the trendValue column based on whether or not the other columns are null. The kicker is, I want it to select the column that is used to update the trend value in this order:
1. If prev15 is not null, use this
2. If prev30 is not null, use this
3. If prev45 is not null, use this
4. If prev60 is not null, use this
5. If they are all null, leave as null
I know it would be easy to do with a cursor, but is there any other way?
Thanks,
May 21, 2012 at 8:16 am
You don't need a cursor at all. Use COALESCE function:
UPDATE myTable SET RequiredColumn = COALESCE(prev15, prev30, prev45, prev60)
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply