February 13, 2009 at 6:01 am
I am trying to select rows from a table using a column that I want to compare to another column but the column being compared is not always the same column. Here are the columns in the table but I am not sure how to make the select change which column it compares to determine if record is selected.
CaltLT, Col1, Col2, Col3, Col4
When CalcLT is 1 I want to select row if Col1 is < 0
When CalcLT is 2 I want to select row if Col2 is < 0
When CalcLT is 3 I want to select row if Col3 is < 0
When CalcLT is 4 I want to select row if Col4 is < 0
Thanks for your help.
vmon
February 13, 2009 at 6:14 am
SELECT *
FROM [MyTable]
WHERE ((CASE CalcLT
WHEN 1 THEN Col1
WHEN 2 THEN Col2
WHEN 3 THEN Col3
WHEN 4 THEN Col4
END) < 0)
February 13, 2009 at 6:52 am
Thanks for the help
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply