Home All Groups Group Topic Archive Search About
Author
31 Dec 2005 2:08 PM
Savas Ates
I have two tables.. They are both identical..

I want to select some fields from one and insert to another one.
How can i do it ?

SELECT urunadi INTO  [AlisverissaatiXML].[dbo].[urunler]  FROM
[Kangurum].[dbo].[urunler] WHERE urunadi='ROMANSON PHIL MEETY'

It returns

The object name 'AlisverissaatiXML.dbo.urunler.' contains more than the
maximum number of prefixes. The maximum is 2.

Author
31 Dec 2005 2:15 PM
David Portas
Savas Ates wrote:
> I have two tables.. They are both identical..
>
> I want to select some fields from one and insert to another one.
> How can i do it ?
>
> SELECT urunadi INTO  [AlisverissaatiXML].[dbo].[urunler]  FROM
> [Kangurum].[dbo].[urunler] WHERE urunadi='ROMANSON PHIL MEETY'
>
>  It returns
>
> The object name 'AlisverissaatiXML.dbo.urunler.' contains more than the
> maximum number of prefixes. The maximum is 2.

INSERT INTO [AlisverissaatiXML].[dbo].[urunler] (col1, col2, col3, ...)
SELECT col1, col2, col3, ...
  /* ... list the columns you require */
  FROM [Kangurum].[dbo].[urunler]
  WHERE urunadi='ROMANSON PHIL MEETY' ;

--
David Portas
SQL Server MVP
--
Author
31 Dec 2005 2:30 PM
Jens
Hi Savas,

Select into is used if you want to create a new table based on the
provided schema of the selected columns in your statement. If you want
to insert data into an exsiting table you should rather use INSERT
INTO:

INSERT INTO [AlisverissaatiXML].[dbo].[urunler]
(
  urunadi
)
SELECT urunadi
FROM [Kangurum].[dbo].[urunler]
WHERE urunadi='ROMANSON PHIL MEETY'


HTH, Jens Suessmeyer.
Author
31 Dec 2005 4:01 PM
Aaron Bertrand [SQL Server MVP]
> INSERT INTO [AlisverissaatiXML].[dbo].[urunler]
> (
>  urunadi
> )
> SELECT urunadi
> FROM [Kangurum].[dbo].[urunler]
> WHERE urunadi='ROMANSON PHIL MEETY'

Or in this trivial case:

INSERT [AlisverissaatiXML].[dbo].[urunler]
(
    urunadi
)
SELECT 'ROMANSON PHIL MEETY'

Show quote
:-)

AddThis Social Bookmark Button