Announcement

Collapse
No announcement yet.

UPDATE SQL statement

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • UPDATE SQL statement

    Hello friends,

    I want to update all F (female) and M (Male) values (change all F values to M and vice versa) as per following table.

    Id >> Name >> Sex >> Salary
    1 >> A >> m >> 5000
    2 >> B >> f >> 2500
    3 >> C >> m >> 7500
    4 >> D >> f >> 800

    How should I write the query to update the values?

  • #2
    Hi,
    Go through with following SQL statement

    UPDATE Gender SET sex = CASE sex WHEN 'm' THEN 'f' ELSE 'm' END

    Comment


    • #3


      I have a plugin to SSMS that warns me if I'm about to execute a DELETE or UPDATE without a WHERE clause, and it's saved me on a couple of occasions.





      Last edited by winkibili; 27-05-22, 10:40 AM.

      Comment

      Working...
      X