0

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

1
  • Nevermind. Answers came in whilst I was crafting this comment. Commented Apr 23, 2010 at 14:58

2 Answers 2

4

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
Sign up to request clarification or add additional context in comments.

Comments

3
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

3 Comments

You diamond, remembered for next time! Have a good weekend mate.
If you found the answer helpful, an upvote and accepting the answer would be appreciated ;)
Of course, standard procedure, the ten min wait is slightly annoying on the accept :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.