3
Reply

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.

Sukesh Marla

Sukesh Marla

12y
2.6k
2
Reply

    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)

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

    You all have entered correct