Community discussion forum

Single Update Query for one column with two values

  • 1 year ago

    Dear  All,

             I have bellow table structure with two column id and status (just imaginary). Status column contains only two values M or F.

            Id  Status 

            1    M
            2    F
            3    M
            4    F
            5    F
            6    M
            7    F
            8    M
            9    F
            10    M

            Now I want one single update query to update status column values vice versa. In other words M is updated with F and F is updated with M. I don't want any sub query, joins or union. Only one single query.

            Thanks in advance.

    Regards,

    Pradip
     

  • 1 year ago

    update StatusTable
    set Status = case when Status='M' then 'F' else 'M' end

    QED
     

  • 1 year ago

     Dear Joe,

        Thanks for your quick reply. Through your query I had solved my problem.

        I want to know that is there any other solution to this query?
     

    Regards,

    Pradip 

Post a reply

Enter your message below

Sign in or Join us (it's free).

Want to stay in touch with what's going on? Follow us on twitter!