Saturday, 20 October 2018

Swap Values of Two Columns in SQL Server



create table Student 
( 
      StudentID Int identity primary key, 
      FirstName varchar(30), 
      LastName varchar(30), 
      Marks Int 
) 
 
Insert into Student(FirstName,LastName,Marks) Values('Nitin','Tyagi',400) 
Insert into Student(FirstName,LastName,Marks) Values('Ajay','Sharma',300) 
Insert into Student(FirstName,LastName,Marks) Values('Vikrant','Sharma',100) 

select * from Student

update Student
set FirstName=LastName,
    LastName=FirstName

select * from Student


No comments:

Post a Comment