Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
Log in  ::  Register  ::  Not logged in
Home       Members    Calendar    Who's On

Add to briefcase

How to select first non Null value from multiple fields Expand / Collapse
Posted Tuesday, April 16, 2013 9:54 AM


Group: General Forum Members
Last Login: Tuesday, December 16, 2014 11:50 AM
Points: 199, Visits: 497
what is the best way to select fist non Null value from mutliple fiels K1,.... K3, I heard about case, but still can't figure out how to use single case fro multiple columns?

Appreciate your help.

select * from T01-- source table::::
PK K1 K2 K3
2 Bravo
3 Charlie
1 Alpha
48 Whiskey

--wanted output:
select PK, case (.....) from T01
1 Alpha
2 Bravo
3 Charlie
48 Whiskey

Post #1442826
Posted Tuesday, April 16, 2013 10:10 AM



Group: General Forum Members
Last Login: Yesterday @ 2:05 PM
Points: 13,327, Visits: 12,820
Look at coalesce. That is exactly what it is intended for.


Need help? Help us help you.

Read the article at for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1442837
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse