Solved

sql query help fitst not null

Posted on 2011-02-27
3
225 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 143

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

Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

Question has a verified solution.

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

Suggested Solutions

Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

739 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