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

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

Starting Member

47 Posts

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

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

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.

(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  
 New 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.05 seconds. Powered By: Snitz Forums 2000