Solved

sql query help fitst not null

Posted on 2011-02-27
3
226 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

Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

Question has a verified solution.

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

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.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

691 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