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

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 how to determine the first column with null value

Author  Topic 

jayram
Starting Member

47 Posts

Posted - 2013-02-22 : 15:54:01
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

98 Posts

Posted - 2013-02-22 : 16:05:24
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
   

- Advertisement -