2012年2月16日星期四

Any easy way of getting a columnlist for use with an INSERT statement

Hi
I'm having some data that I need to copy from one table to another using an
INSERT statement. I'm wondering if there's an easier way to enter the column
list than having to type it in manually? In this case the table has about 20
columns (..of course with a lot of odd names...) and I find a bit
cumbersome to type all these in by hand, so hopefully some of you knows an
easier way of doing it?
Regards
SteenIn Query Analyzer, right-click on the table in the Object Browser. Mouse
over "Script Object to New Window as" and click "Insert".
"Steen Persson" <SPE@.REMOVEdatea.dk> wrote in message
news:erbYBVZmEHA.3712@.TK2MSFTNGP15.phx.gbl...
> Hi
> I'm having some data that I need to copy from one table to another using
an
> INSERT statement. I'm wondering if there's an easier way to enter the
column
> list than having to type it in manually? In this case the table has about
20
> columns (..of course with a lot of odd names...) and I find a bit
> cumbersome to type all these in by hand, so hopefully some of you knows an
> easier way of doing it?
> Regards
> Steen
>|||Enjoy this :
select ' ' + T2.name + ','
from sysobjects T1, syscolumns T2
where
T1.type ='U'
and T1.Id = T2.Id
And T1.name = 'YourTable'
order by colid
Don
>--Original Message--
>Hi
>I'm having some data that I need to copy from one table
to another using an
>INSERT statement. I'm wondering if there's an easier way
to enter the column
>list than having to type it in manually? In this case the
table has about 20
>columns (..of course with a lot of odd names...) and I
find a bit
>cumbersome to type all these in by hand, so hopefully
some of you knows an
>easier way of doing it?
>Regards
>Steen
>
>.
>|||Thanks...that was just what I wanted.
Regards
Steen
David Portas wrote:
> If you are using SQL2000 you can drag the list of column names from
> the Object Browser in Query Analyzer. Just click on the word
> "columns" in the tree and drag it into the editing window.
> --
> David Portas
> SQL Server MVP

没有评论:

发表评论