Hello,
I'm trying to insert into another table where select clause contains a join
with another table. However the number of columns of the source does not
match with the destination table.
How can i fix this without specifying all columns?Why wouldn't you want to specify the required columns? I strongly
recommend you always list the column names. In the long run it makes
your code much more stable and maintainable.
Your options are basically to list only the required columns or to
create a view containing only the required columns and select from that
instead. Of course you'll then have to list the columns in the view...
Either way, you can save yourself a lot of typing by clicking and
dragging the column name list from the Object Browser in query
analyzer.
David Portas
SQL Server MVP
--|||Hi David,
Of course i don't want to type a lot. But the only difference in the
sourcetable is just one field and that field comes from another database.
Will it work?
"David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
news:1109605400.131290.70710@.f14g2000cwb.googlegroups.com...
> Why wouldn't you want to specify the required columns? I strongly
> recommend you always list the column names. In the long run it makes
> your code much more stable and maintainable.
> Your options are basically to list only the required columns or to
> create a view containing only the required columns and select from that
> instead. Of course you'll then have to list the columns in the view...
> Either way, you can save yourself a lot of typing by clicking and
> dragging the column name list from the Object Browser in query
> analyzer.
> --
> David Portas
> SQL Server MVP
> --
>|||Will it work? Maybe it will. But I don't believe it is guaranteed to work
unless you specifically list the columns in both lists. Is it worth the
risk? That's up to you but I certainly would not want to put into
production code that I was not sure was correct.
Andrew J. Kelly SQL MVP
"Jason" <jasonlewis@.hotrmail.com> wrote in message
news:ucxlZ$aHFHA.3588@.TK2MSFTNGP14.phx.gbl...
> Hi David,
> Of course i don't want to type a lot. But the only difference in the
> sourcetable is just one field and that field comes from another database.
> Will it work?
>
> "David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
> news:1109605400.131290.70710@.f14g2000cwb.googlegroups.com...
>|||Will what work? If there are fewer columns in the SELECT statement than
in the target table then you have to list the columns in the INSERT
list and/or the SELECT list - SQL Server won't guess which columns you
want to keep.
David Portas
SQL Server MVP
--|||You can copy and paste the column names out of EM (Design Table) and into
Excel, then use Excel to concatenate them into one long comma-separated
string for you. You can then copy and paste that one long string into your
editing program to eliminate some typing.
Thx
Mike C
"Jason" <jasonlewis@.hotrmail.com> wrote in message
news:ucxlZ$aHFHA.3588@.TK2MSFTNGP14.phx.gbl...
> Hi David,
> Of course i don't want to type a lot. But the only difference in the
> sourcetable is just one field and that field comes from another database.
> Will it work?
>
> "David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
> news:1109605400.131290.70710@.f14g2000cwb.googlegroups.com...
>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment