views:

51

answers:

2

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

+3  A: 
update EmailAddresses set
    Priority1 = case GENDER__C
        when 'Female' then 1
        when 'F' then 1        
        when 'Male' then 2
        when 'M' then 2
        else 3 end
Adam Robinson
You diamond, remembered for next time! Have a good weekend mate.
Yoda
If you found the answer helpful, an upvote and accepting the answer would be appreciated ;)
Adam Robinson
Of course, standard procedure, the ten min wait is slightly annoying on the accept :)
Yoda
+4  A: 

Change it to a CASE statement :

UPDATE EmailAddresses
SET Priority1 = Case
    When GENDER_C IN ('Female', 'F') Then '1'
    When GENDER_C IN ('Male', 'M') Then '2'
    Else '3'
End
FROM EmailAddresses
CodeByMoonlight