-
Combining data Fields
I've got 2 fields A and B. I want to test the values in each field and return a single field YES or NO. At the moment I have 2 case statements but I just want to return a single Alt_Code value.
Thanks in advance.
Select ...,
CASE A
WHEN '1T' THEN 'YES'
WHEN '20' THEN 'YES'
WHEN '7Y' THEN 'YES'
WHEN '8C' THEN 'YES'
ELSE 'NO'
END Alt_Code,
CASE B
WHEN 'ID' THEN 'YES'
WHEN 'MS' THEN 'YES'
ELSE 'NO'
END Alt_Code_1
From ...
-
I'm fairly new to SQL but not new to programming
How about:
CASE
WHEN A='1T' THEN 'YES'
WHEN A='20' THEN 'YES'
WHEN A='7Y' THEN 'YES'
WHEN A='8C' THEN 'YES'
WHEN B='ID' THEN 'YES'
WHEN B='MS' THEN 'YES'
ELSE 'NO'
END
Hope that helps!
From Suhada
-
Your "not new to programming" example just created a dependency between A and B where (maybe) one did not exist before. The first case that matches in your example stops processing. Should have listed combinations of A and B in your example.
-
stecal,
Thanks for your post.
Now you point out the dependency, I see you are right.
I'd been confused by the SQL syntax - apologies.
I'm now not sure if the original question gives enough detail about what is wanted. Perhaps ryand09, you could explain in more detail what you want.
Or stecal - maybe you understand and can offer a solution?
Best wishes
Suhada
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|