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
 General SQL Server Forums
 New to SQL Server Programming
 My Question

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2007-03-05 : 10:47:19
Guddu writes "Hi i am trying to swap the column names of a table. Consider a table having employee details and cols as First_Nane,Second_Name,Age,Employee_Id,Address. While entering data i have entered The details of FirstName in the Second_Name column and of the SecondName in the First_Name. Now i need to swap the column names without using a temp table or a column name. Is it possible. Something like the swap we perform in C without a temp variable."

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-03-05 : 10:53:10
[code]declare @t table
(
a varchar(10),
b varchar(10)
)

insert @t
select 'aa', 'bb' union all
select 'pp', 'qq' union all
select 'xx', 'yy'

-- before update
select * from @t

update @t
set a = b, b = a

-- after update
select * from @t
[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page
   

- Advertisement -