need help with a query

  • a friend of mine was asked this question in an interview.

    a table has a column gender with values M and F.

    need to write a query to switch these genders i.e put M where F and F where M.

    can this be done without using a cursor/while loop?

    thanks

    Pankaj

  • UPDATE mytable

    SET gender = CASE WHEN gender = 'F' THEN 'M'

    WHEN gender = 'M' THEN 'F'

    ELSE gender

    END

    Regards,

    Willem
    http://wschampheleer.wordpress.com[/url]

  • I hope Willem gets the job. 😉

    __________________________________________________

    Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
    Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply