Update a Column

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • neelam26
    New Member
    • May 2007
    • 12

    Update a Column

    Hi,

    I have a table named Employee having column as Gender storing values 'M' and 'F' accordingly.Hel p me to write a update query where the 'M values n the field are updated to 'F' and vice versa

    Thanks and regards
    Neelam
  • frozenmist
    Recognized Expert New Member
    • May 2007
    • 179

    #2
    Hi Neelam,

    You can use a case statement for this.
    The query can be like:
    Code:
    update Employee set Gender=
       case when Gender='M' then 'F' else  'M'
       end
    Hope this answers your problem.
    Cheers

    Comment

    • neelam26
      New Member
      • May 2007
      • 12

      #3
      Hi,

      Hey thanx a lot...it worked...ws bit cnofused...bt neways

      Originally posted by frozenmist
      Hi Neelam,

      You can use a case statement for this.
      The query can be like:
      Code:
      update Employee set Gender=
         case when Gender='M' then 'F' else  'M'
         end
      Hope this answers your problem.
      Cheers

      Comment

      • frozenmist
        Recognized Expert New Member
        • May 2007
        • 179

        #4
        Hi Neelam,
        What was the confusion about?
        The case statement returns M if the current value is F and Vice versa.
        Then just update using this returned value.

        Cheers

        Comment

        Working...