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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 ALTERING TABLE

Author  Topic 

SKP
Starting Member

34 Posts

Posted - 2006-08-15 : 07:14:48
Hi!, I have a table called TestTable with three columns Col_A,Col_B,Col_C .I need to alter this table, I have to drop all these three columns and create a new column called Col_D, this column will have its values as the name's of last three columns,

Old Table looks like:
Col_A,Col_B,Col_C

New Table should look like:
Col_D
-----
Col_A
Col_B
Col_C

Can any of you please help me on writting a T-Sql to achieve the desired goal?

Thank you.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-08-15 : 07:19:46
[code]ALTER TABLE TestTable
ADD Col_D VARCHAR(50)

INSERT TestTable
(
Col_D
)
SELECT 'Col_A' UNION ALL
SELECT 'Col_B' UNION ALL
SELECT 'Col_C'

ALTER TABLE TestTable
DROP COLUMN Col_A

ALTER TABLE TestTable
DROP COLUMN Col_B

ALTER TABLE TestTable
DROP COLUMN Col_C[/code]
Peter Larsson
Helsingborg, Sweden
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-08-15 : 07:38:51
quote:
Originally posted by SKP

Hi!, I have a table called TestTable with three columns Col_A,Col_B,Col_C .I need to alter this table, I have to drop all these three columns and create a new column called Col_D, this column will have its values as the name's of last three columns,

Old Table looks like:
Col_A,Col_B,Col_C

New Table should look like:
Col_D
-----
Col_A
Col_B
Col_C

Can any of you please help me on writting a T-Sql to achieve the desired goal?

Thank you.



What are you trying to do ? This is a bit unusual if I did not misunderstood you.


KH

Go to Top of Page

SKP
Starting Member

34 Posts

Posted - 2006-08-15 : 08:51:29
Thanks Peter.
Go to Top of Page
   

- Advertisement -