Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 how to determine the first column with null value
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

jayram
Starting Member

47 Posts

Posted - 02/22/2013 :  15:54:01  Show Profile  Reply with Quote
Hello

I have a table with 7 columns like Cumulative_cnt, AX1, AX2, AX3, AX4, AX5, POS

i want to find the first AX column with a 'null' and assign that column number to POS as a value

for e.g. if AX3 has the first null value then POS is assigned a value 3.

table is as follows

AX1-AX5 are varchar
all columns after the first column with a Null is Null
all columns preceding the first column with Null has a value
at least one column has a value and is not null usually AX1

notmyrealname
Yak Posting Veteran

98 Posts

Posted - 02/22/2013 :  16:05:24  Show Profile  Reply with Quote
You could use a computed column for POS.

Formula:
(case when [AX1] IS NULL then (1) when [AX2] IS NULL then (2) when [AX3] IS NULL then (3) etc... end)
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000