A data table of values of the two swapped

As said header, the data needs to be reversed 2, the value stored in row 2 of column 1, to the value stored in row 1 column 2.

 

 

How to achieve two methods:

The first one kind of column names to be modified, changed the name1 name2, name1, name2 changed to:

 

sp_rename 'Q3.name1',temp_name1,'column'
GO
sp_rename 'Q3.name2',temp_name2,'column'
GO
sp_rename 'Q3.temp_name1',name2,'column'
GO
sp_rename 'Q3.temp_name2',name1,'column'
GO

SELECT * FROM Q3
GO
View Code

 

The second method, using the update operation:

 

UPDATE Q3 SET name1 = name2, name2 = name2
GO
SELECT * FROM Q3
GO
View Code

 

Guess you like

Origin www.cnblogs.com/insus/p/12107750.html