Sunday, 5 May 2013


Method 1: Using CASE Statement

I believe this is going to be the most popular solution as we are all familiar with CASE Statement.
UPDATE SimpleTableSET Gender CASE Gender WHEN 'male' THEN 'female' ELSE 'male' ENDGOSELECT *FROM SimpleTable
GO

Method 2: Using REPLACE  Function

I totally understand it is the not cleanest solution but it will for sure work in giving situation.
UPDATE SimpleTableSET Gender REPLACE(('fe'+Gender),'fefe','')GOSELECT *FROM SimpleTable
GO

Method 3: Using IIF in SQL Server 2012

If you are using SQL Server 2012 you can use IIF and get the same effect as CASE statement.
UPDATE SimpleTableSET Gender IIF(Gender 'male''female''male')GOSELECT *FROM SimpleTable
GO

No comments:

Post a Comment