SQL Question July 10, 2013 Get link Facebook X Pinterest Email Other Apps Suppose in a table we have 1 column now column1 has values a b a b a b Table name : Table1 Column Name : Column1 Question : update table1 where 'a' should be replaced with 'b' and 'a' should be replaced with 'd' Comments SwatiMay 23, 2014 at 10:55 AMSET @value1 = 'b'SET @value2 = 'a'UPDATE table1 SET val = REPLACE(@value1 + @value2,val,'')select REPLACE(@value1 + @value2,val,'') from table1ReplyDeleteRepliesReplySandeep Mhatre S/w EngineerJanuary 7, 2015 at 1:20 PMEven simple way to update the value as follows :update table1 set Column1 = Case when 'a' then 'b' When 'b' then 'a'end ReplyDeleteRepliesReplyAdd commentLoad more... Post a Comment
SET @value1 = 'b'
ReplyDeleteSET @value2 = 'a'
UPDATE table1 SET val = REPLACE(@value1 + @value2,val,'')
select REPLACE(@value1 + @value2,val,'') from table1
Even simple way to update the value as follows :
ReplyDeleteupdate table1
set Column1 =
Case when 'a' then 'b'
When 'b' then 'a'
end