Tuesday, 9 July 2013

Swap values of two columns in sql server

Hi ,
        Suppose In case of data uploading or data inserting you done mistake to upload or insert
data of one column to other then you want to swap the values of that two columns of a table
in SQL Server.
Suppose you have a #emp_info table in the database with the following data and
you want to interchange the values of empno and then how do you do?

r
create table #emp_info (empno int,ename varchar(100),manage_id int)

insert into #emp_info (empno,ename ,manage_id )values(1,'sandip',3)
insert into #emp_info (empno,ename ,manage_id )values(2,'harshal',1)
insert into #emp_info (empno,ename ,manage_id )values(3,'aditya',4)
insert into #emp_info (empno,ename ,manage_id )values(4,'pranav',2)
insert into #emp_info (empno,ename ,manage_id )values(5,'ajit',3)

Your Data ::

select * from #emp_info

Don't worry, to do this task, you need to just write a simple update query for Customer table like as :

UPDATE #emp_info SET empno=manage_id , manage_id=empno


Other Popular Posts ::

No comments:

Post a Comment

8451831077