Subash B Subash B - 2 months ago 5
SQL Question

A column contains `Male` and `Female` and i want to change all female into male and viceversa

A column contains

Male
and
Female
and i want to change all female into male and viceversa.(I want to do this in single update.)

Thanks in advance.

Answer

Try This:

UPDATE YourTableName SET ColumnName = CASE ColumnName  WHEN 'm' THEN 'f' ELSE 'm' END

I hope it will helpful for you.

And try (IFF) if you using sql-server 2012.

Try this link, It will help you about IIf in server 2012

http://sqlhints.com/2013/06/15/iif-logical-function-in-sql-server-2012/

Comments