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

order by to return null values Expand / Collapse
Author
Message
Posted Monday, January 26, 2009 12:17 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, December 9, 2010 2:28 PM
Points: 42, Visits: 79
I have 3 columns in one table.
Col1, Col2, Col3.
The data in these columns has data, and some null values. For Eg:

Col1 Col2 Col3
Data1 Data2 Data3
null null null
Data1a Data2a null
Data1b null Data3a
null Data2b Data3b

I need to run a Select query, such that the results return with where all the 3 columns have null values, then atleast 1 or more null values, and then with data in all columns.

Let me know how I can write a query to return data

Thanks
Post #643632
Posted Monday, January 26, 2009 12:23 PM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Yesterday @ 6:25 PM
Points: 3,121, Visits: 11,397
select
*
from
MyTable
order by
case
when col1 is null and col2 is null and col3 is null
then 1
when col1 is null or col2 is null or col3 is null
then 2
else 3
end

Post #643639
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse