Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 Query to exchange the values of the columns in tlb

Author  Topic 

Swati Jain
Posting Yak Master

139 Posts

Posted - 2007-09-14 : 02:20:28
Hello All,

In a table there are 2 columns named column1 and column2
by mistake , values of column1 was entered in column2 and vise versa

what query to execute, to exchnage values of columnc in table?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-09-14 : 03:13:54
DECLARE @Temp INT

UPDATE Table1
SET @Temp = Col1, Col1 = Col2, Col2 = @Temp



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-09-14 : 03:33:02
[code]declare @a table (i int, j int)

insert @a
select 1, 4

select 'before', * from @a

UPDATE @a
SET i = j, j = i

select 'after', * from @a[/code]


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -