简体   繁体   中英

SQL Server Case expression conditions

I am currently working on a data flow and have been given a specific requirement that i am trying to complete.

In my table I have a column which is partially NULL due to a couple of reasons.

What I'm trying to do is write a case expression within my select statement that has two conditions:

When NULL use a different value from another column (which is pulled from another table using a join)

If the column is still NULL (in both cases) then use a different value from another column in the table which will ensure the column is populated.

So basically, if it's NULL do this, if its still NULL , then do this which will mean my column is populated as i intend.

I've been playing around but have been unable to produce the required result. Is this something that can be achieved using a CASE expression ?

Any help/advice would be appreciated.

Thanks.

You are describing the coalesce() function:

coalesce(col1, col2, col3)

You can use this in either a select or update .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM