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
 General SQL Server Forums
 New to SQL Server Programming
 Create table from table error

Author  Topic 

vamsimahi
Starting Member

29 Posts

Posted - 2008-04-11 : 12:32:23
Hi,

I am new to SQL and i am trying to create a table from a table. below is my query but im getting an error

CREATE TABLE Production.TransactionHistoryArchive1 AS
(SELECT ProductID,SUM(Quantity) QuantitySum,SUM(LineItemTotalCost) TotalCostByID FROM Production.TransactionHistoryArchive
GROUP BY ProductID)


error:
Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'AS'.

nathans
Aged Yak Warrior

938 Posts

Posted - 2008-04-11 : 12:34:44
read in BOL about SELECT INTO

Nathan Skerl
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-04-11 : 12:35:26
1)Create table with same structure
2) Insert into Production.TransactionHistoryArchive1
SELECT ProductID,SUM(Quantity) QuantitySum,SUM (LineItemTotalCost) TotalCostByID FROM Production.TransactionHistoryArchive
GROUP BY ProductID

Or use Export/Import Wizard.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-04-11 : 12:37:41
You cant create a table like this. AS nathans pointed out use SELECT INTO

Go to Top of Page

vamsimahi
Starting Member

29 Posts

Posted - 2008-04-11 : 12:42:06
thank you nathan it worked...
Go to Top of Page
   

- Advertisement -