Solved

sql query help fitst not null

Posted on 2011-02-27
3
221 Views
Last Modified: 2012-05-11
I have a table

ID   Rank1 Rank2 Rank3
112  1         2            Null

I want to write a query that shows the rank for the above example it should display result as 2
ID   Rank1 Rank2 Rank3
112  1         Null        3

for above it should show result as 1

ID   Rank1 Rank2 Rank3
112  Null        Null       2

for above it should show  result as zero

ID   Rank1 Rank2 Rank3
112  Null        2        2


for above it should display 0




As you can see i want to show the lowest rank before first null




0
Comment
Question by:Angela4eva
3 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 34992522
select case when rank1 is null then 0
  when rank2 is null then rank1
  when rank3 is null then rank2
  else rank3 end
  from yourtable
0
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 34992541
select case
when rank1 is null then 0
when rank2 is null then 1
when rank3 is null then 2
else null
 end Result
  from YourTable

Raj
0
 

Author Closing Comment

by:Angela4eva
ID: 34992651
thank you
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now