Community discussion forum

Single Update Query for one column with two values

  • 6 months 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
     

  • Advertisement

    Simply the fastest line-level profiler for .NET ever

    “The low overhead means it has minimal impact on the execution of my program”
    Mark Everest, Development Team Leader, Renault F1 Team Ltd.

    Try out the new ANTS Profiler 4 for yourself. Download your 14-day trial now

  • 6 months ago

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

    QED
     

  • 6 months 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).