June 21, 2013 at 4:39 am
Hi
I figured I'd put this out there before I leave for work...
looking to see if I can do a nested if like this:
if value1 = '1' and value2 = '2' then 'A'
if value1 = '1' and value9 = '2' then 'B' else
if value99 = 'l' and value9 = 'x' then 'C' end as?
What I'm trying to do is find values between 2-3 fields then assign a code.
also one supersede the other , so if first and second if conditions are met i want the first if value
Thanks In Advance
Joe
June 21, 2013 at 4:44 am
Hi
If you're trying to do this in T-SQL then what you need is a case statement.
SELECT
CASE
WHEN value1 = 1 AND value2 = 2 THEN 'A'
WHEN value1 = '1' and value9 = '2' then 'B'
WHEN value99 = 'l' and value9 = 'x' THEN 'C'
ELSE '<CatchAllValue>' -- Optional
END
FROM
foo
WHERE
bar = <condition>
Hope that helps.
Thanks,
Simon
June 21, 2013 at 8:19 am
Thanks Simon
Works great..
Bad week I should have known that...
Thanks Again
June 21, 2013 at 10:18 am
No worries... we all have them.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply