0

I have a temp table where i have changed some values in the database and am trying to nsert these back into the real table but it is not working I have this below:

SELECT * INTO dbo.PackageProduct FROM #PackageP

where #PackageP is my temp table

I am getting this error after the second run:

There is already an object named 'PackageProduct' in the database.
user667430
  • 1,487
  • 8
  • 38
  • 73
  • [INSERT INTO vs SELECT INTO](http://stackoverflow.com/questions/6947983/insert-into-vs-select-into) – bummi Sep 04 '14 at 15:12

4 Answers4

4

If the table already exists you have to use INSERT as SELECT...INTO creates a new table:

INSERT dbo.PackageProduct (<columns...>)
SELECT (<columns...>) FROM #PackageP
jpw
  • 44,361
  • 6
  • 66
  • 86
1

TRY

INSERT INTO dbo.PackageProduct SELECT * FROM #PackageP
SRahmani
  • 348
  • 1
  • 5
  • 17
0

Assuming you've got the same number and order of columns in both tables try this:

INSERT INTO dbo.PackageProduct
SELECT *
FROM #PackageP
Dave.Gugg
  • 6,561
  • 3
  • 24
  • 43
Piotrek
  • 3
  • 3
0

If you do select * into ... it will create a table, if the same name already exist then it will show error, and the error clearly identifies that there is already a object (table/view/proc... ) in the database. check with some other name or check the existing object is not required then drop it and then use your query or insert it into the table(if both your temp table and the existing object structure is same and it is a table).

ram_sql
  • 404
  • 2
  • 9