I have an instruction that SELECTs distinguishes rows from a table with an index of two values
SELECT distinct Reference, Value1, Value2, Value3, Value4 FROM [tblHistory]
Where Reference is an index with a different Project field. For a specific system, this data is inserted into another table, using only the link as an index, because Value1 to Value4 SHOULD always be the same for the same directory, but at about 1/500 this is not so.
In the case where there is a duplicate Reference AND in one or more of the fields Value1-Value4, I need to select the row with the most complete fields Value1-Value4, since they are often NULL. If all instances have the same number of filled columns, I can return the found first row.
Besides using temporary tables and code like
case when Value1 is null then 1 else 0 end
+ case when Value2 is null then 1 else 0 end
+ case when Value3 is null then 1 else 0 end
+ case when Value4 is null then 1 else 0 end
as CountOfNulls
Is there a way to filter the data, so I only get the most populated string?
I am running MS SQL Server 2000.
Pcurd source
share