Wednesday, November 13, 2013

Swap column values in sql server 2008

Suppose we have a table named USER with 3 columns: USERID, USERName, USERAddress.

              USERID: int 
USERName: varchar(100)
USERAddress: varchar(100)


Swap with the temporary variable:
-----------------------------------------------


DECLARE @temp AS varchar(10)
 
UPDATE USER SET @temp=USERAddress, USERAddress=USERName, USERName=@temp
 


Hope freshers will find it helpful :)

No comments:

Post a Comment