Insert into table from #tempTable fails

I just take the data from the table and insert it into #tempTable, then delete the data and insert it back into the table. I get "Insert error: Column name or number of given values ​​does not match table definition." Error.

Here are the lines that I am running.

SELECT * INTO #tempTable FROM dbo.ProductSales 

SELECT * FROM #tempTable

DELETE FROM dbo.ProductSales

INSERT INTO dbo.ProductSales SELECT * FROM #tempTable

      

Any idea?

+2


a source to share


1 answer


If ProductSales

has a column of identity or timestamp / row, you won't be able to use SELECT *

for insert. Instead, list the columns skipping the identity column:



Insert ProductSales(Col1, Col2....
Select Col1, Col2...
From #tempTable

      

+6


a source







All Articles