Sukesh Marla
Consider you have table Say TblEmployee with a column say EmployeeName which contain Records as A,B,A,A,B,C,B,C,Ayour task is to write a query which will change the EmployeeName A to B and B to A.
By Sukesh Marla in SQL Server on Aug 12 2012
  • Dasharath Vishwakarma
    May, 2014 19

    CREATE table #TbleEmployee (EmployeeName varchar(10))insert into #TbleEmployee(EmployeeName)VALUES('A'),('B'),('A'),('A'),('B'),('C'),('B'),('C'),('A')update #TbleEmployee SETEmployeeName=(CASE EmployeeName WHEN 'A' THEN 'B' WHEN 'B' THEN 'A' ELSE EmployeeName END)

    • 3
  • Sukesh Marla
    Aug, 2012 12

    update TblEmployee 
    set EmpName = (CASE 
    WHEN EmpName='A' THEN 'B'
    WHEN EmpName='B' THEN 'A'
    ELSE EmpName
    END)

    • 3
  • Divyanshu Tripathi
    Aug, 2015 18

    You all have entered correct

    • 1
  • Rajeev Kumar
    Jul, 2023 11

    update TblEmployee set EmpName = EmpName=’A’ THEN ‘B’
    WHEN EmpName=’B’ THEN ‘A’
    ELSE EmpName
    END

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS