Reputation: 13
This is my first time to write SQL and I try to find out the wrong but I can't find out which place is wrong.
My version of SQL Server is SQL Server Management Studio 17
CREATE TABLE nohours AS
(SELECT Dnumber, SUM(Hours) FROM DEPARTMENT,PROJECT,WORKS_ON
WHERE Pno=Pnumber AND Dnum=Dnumber
GROUP BY Dnumber
);
and I got an error:
Msg 102, Level 15, State 1
Incorrect syntax near '('
Upvotes: 1
Views: 3866
Reputation: 169
CREATE TABLE nohours
(
Dnumber INT,
TotalHours BIGINT
)
GO
INSERT INTO nohours
(
Dnumber ,
TotalHours
)
SELECT Dnumber, SUM(Hours) AS TotalHours
FROM DEPARTMENT,PROJECT,WORKS_ON
WHERE Pno=Pnumber AND Dnum=Dnumber
GROUP BY Dnumber
Upvotes: 1
Reputation: 111
SELECT Dnumber, SUM(Hours) as Hours
INTO nohours
FROM DEPARTMENT,PROJECT,WORKS_ON
WHERE Pno=Pnumber AND Dnum=Dnumber
GROUP BY Dnumber
This will create the nohours
table from the results of the SELECT
. The MS documentation on the command is here - https://learn.microsoft.com/en-us/sql/t-sql/queries/select-into-clause-transact-sql
Upvotes: 1