larrydavid
Programmer
Hello, I have a stored proc with case statements where there are two conditions which is covered by a regular CASE statement:
[TableValue1] = CASE
WHEN Value1 IS NOT NULL THEN Value1
ELSE null
END
But now I have a situation where it can be any of three possible conditions:
CASE WHEN Value1 IS NOT NULL THEN Value1
CASE WHEN Value2 IS NOT NULL THEN Value2
CASE WHEN Value3 IS NOT NULL THEN Value3
ELSE null
END
I'm not quite sure how to approach this, because Value 2 can supercede Value1, Value3 can supercede Value 2 and so forth. Can I assume that if I use the fields as they are being selected in ascending order that this order of precendence would happen anyway? Or, do I need to implement nested CASE statements for this to happen the right way? If so, is there an IF-THEN-ELSEIF type of construct I can apply in SQL Server 2005 in a stored proc? I've researched this and see this in SQL Server 2008 but not in SQL Server 2005.
Any help would be most greatly appreciated.
Thanks,
Larry
[TableValue1] = CASE
WHEN Value1 IS NOT NULL THEN Value1
ELSE null
END
But now I have a situation where it can be any of three possible conditions:
CASE WHEN Value1 IS NOT NULL THEN Value1
CASE WHEN Value2 IS NOT NULL THEN Value2
CASE WHEN Value3 IS NOT NULL THEN Value3
ELSE null
END
I'm not quite sure how to approach this, because Value 2 can supercede Value1, Value3 can supercede Value 2 and so forth. Can I assume that if I use the fields as they are being selected in ascending order that this order of precendence would happen anyway? Or, do I need to implement nested CASE statements for this to happen the right way? If so, is there an IF-THEN-ELSEIF type of construct I can apply in SQL Server 2005 in a stored proc? I've researched this and see this in SQL Server 2008 but not in SQL Server 2005.
Any help would be most greatly appreciated.
Thanks,
Larry