lijun
Here is my simplified table/field for illustration purpose.
Id, Date, C1, C2, ..., C50
Id and Date are primary key. C1 to C50 are nullable.
Give Id, Date and a number between 1 to 50 ,say 35, I want to my stored-proc to return the field name and value of the last non-null value before column C35 in the row that is identified by Id and Date. Suppose C34 has value 100, I'd like to return C34 and 100, if C34 is null and C33 is not null with value 95, then I'd like to return C33 and 95...etc.
Since Id and Date are primary key, it can identified a unique row. Now the question is how to easily get the last non-null value
It would be easier if change the table structure but unfortunately it is legacy system and we can't change it.
Thanks.