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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Insert into an existing table?

Author  Topic 

taunt
Posting Yak Master

128 Posts

Posted - 2013-06-11 : 13:33:36
Hello I'm having issues inserting data in an existing table. I do this:

SELECT *
into itemsNRSH
FROM items
WHERE (ReleaseDate = '06/11/2013') AND (StockQty > 0)

That will create a table with the data I want, but if the table is already there it won't. What do I need to try? When I tried:

into into itemsNRSH
SELECT *
FROM items
WHERE (ReleaseDate = '06/11/2013') AND (StockQty > 0)

It says no column list was used. So what am I doing wrong?

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2013-06-11 : 13:38:45
quote:
Originally posted by taunt

Hello I'm having issues inserting data in an existing table. I do this:

SELECT *
into itemsNRSH
FROM items
WHERE (ReleaseDate = '06/11/2013') AND (StockQty > 0)

That will create a table with the data I want, but if the table is already there it won't. What do I need to try? When I tried:

into into itemsNRSH
SELECT *
FROM items
WHERE (ReleaseDate = '06/11/2013') AND (StockQty > 0)

It says no column list was used. So what am I doing wrong?



Are you sure this was the error? Can you copy/paste the exact error thrown by the SQL server?

Cheers
MIK
Go to Top of Page

djj55
Constraint Violating Yak Guru

352 Posts

Posted - 2013-06-11 : 15:04:37
You are correct the select * into will create the table and I assume you ment INSERT INTO itemsNRSH select *?

Are you executing the second query after the first?

djj
Go to Top of Page

taunt
Posting Yak Master

128 Posts

Posted - 2013-06-11 : 17:17:23
Yep it was annoyed that I didn't have the columns mapped. I re did it with the columns in itemsNRSH and items, and it worked.
Go to Top of Page
   

- Advertisement -