?
Solved

sql query help fitst not null

Posted on 2011-02-27
3
Medium Priority
?
228 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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

771 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