Write sql query to exchange FName to LName and LName to FName -
create table Employee
(
ID int Identity(1,1) Primary Key,
FName char,
LName char
)
insert into Employee(FName,LName) values('A','E'),('C','D'),('B','F')
Q1-
update Employee
set FName = LName, LName=FName from Employee e1
where ID = e1.ID
----------------------------------------------------------------------------------------------------
Write sql query to change gender means 'M' should be 'F' and 'F' should be 'M' -
create table EmployeeDetails
(
ID int Identity(1,1) Primary Key,
Name varchar(100),
Gender char,
Address varchar(100)
)
insert into EmployeeDetails(Name,Gender,Address) values('Ashish','M','Delhi'),('Pankaj','M','New Delhi'),('Sohan','M','Ghaziabad'),('Ritika','F','Noida'),('Mannat','F','Merrut'),('Sonali','F','Lucknow')
Q2-
update EmployeeDetails
set Gender = (Case when Gender='M' then 'F' else 'M' end)
No comments:
Post a Comment