Skip to main content

Posts

Showing posts from August, 2013

swap two columns values in sql

There are various methods on net to swap values of two column, tried many of them. This one seems to be working for me:

UPDATE table_name SET A=B, B=@temp WHERE (@temp:=A) ;

Some of the queries that don't work are:

1. DECLARE @temp AS varchar(10)
UPDATE Employee1 SET @temp=LastName, LastName=FirstName, FirstName=@temp

2. UPDATE Employee1 SET LastName=FirstName, FirstName=LastName


NOTE: talking about sql query only, not including SAS etc