Single Update Query for one column with two values

sql server India
  • 12 years 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
     

  • 12 years ago

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

    QED
     

  • 12 years 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).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Programs must be written for people to read, and only incidentally for machines to execute.”