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
 how to create a table with the rows for a table

Author  Topic 

sunsanvin
Master Smack Fu Yak Hacker

1274 Posts

Posted - 2008-05-13 : 07:48:56
Dear all,
i've table tab1 with columns col1 col2

i've 20 rows out put after selecting the data.

i need all the data of col2 as column for a new table. that is tab2.


please guide me in this regard

Vinod
Even you learn 1%, Learn it with 100% confidence.

nr
SQLTeam MVY

12543 Posts

Posted - 2008-05-13 : 07:51:01
Not sure what you mean - can you give an example.
Does col2 contain data that needs to go into tab2 (where) or are you trying to create columns with names hel in col2 - if so where do you get the datatype from?

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

soorajtnpki
Posting Yak Master

231 Posts

Posted - 2008-05-13 : 08:05:03
HI
TRY THIS

SELECT col2 INTO tab2 FROM tab1


ok tanx.....
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-13 : 11:03:32
quote:
Originally posted by sunsanvin

Dear all,
i've table tab1 with columns col1 col2

i've 20 rows out put after selecting the data.

i need all the data of col2 as column for a new table. that is tab2.


please guide me in this regard

Vinod
Even you learn 1%, Learn it with 100% confidence.


is it only column in your new table tab2
if yes, you can use

INSERT INTO tab2
SELECT col2 FROM tab1

IF tab2 has more column you need to specify what values you need to insert for other columns.
And if your attempt is to update the values in one of columns of tab2 from tab1 column, you need to specify on what matching condition do you need to perform update.
Go to Top of Page
   

- Advertisement -