T-SQL Syntax Issue Else if style logic
Posted
by Yoda
on Stack Overflow
See other posts from Stack Overflow
or by Yoda
Published on 2010-04-23T14:52:59Z
Indexed on
2010/04/23
16:03 UTC
Read the original article
Hit count: 277
tsql
|sql-server
Hi guys, two questions today, I'm a busy bee and luckily I have an awesome community at my disposal!
My issue here is this:
I have a field i need to update based on existing field data.
If Gender = F then foo = 1
If Gender = M then foo = 2
If Gender = Male then foo = 2
If Gender = Female then foo = 1
If Gender is not above then foo = 3
Here is what I have:
update EmailAddresses
set Priority1 = '1'
where GENDER__C = 'Female'
update EmailAddresses
set Priority1 = '2'
where GENDER__C = 'Male'
update EmailAddresses
set Priority1 = '1'
where GENDER__C = 'F'
update EmailAddresses
set Priority1 = '2'
where GENDER__C = 'M'
update EmailAddresses
set Priority1 = '3'
where GENDER__C not in (select 'Female', 'Male', 'F', 'M')
Any help much appreciated! And its Friday!! Whoo hoo
© Stack Overflow or respective owner