I am trying to create a simple stored procedure in SQL Server 2005, and am puzzled by a syntax error I am getting.
Both tables have identical structure. tbl_Users_non_61 is empty and ready to receive the data.
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE Make_WEEKLY_SUMMARY
AS
BEGIN
SET NOCOUNT ON;
Select (tbl_Users.UserID
, tbl_Users.RegistrationType
, tbl_Users.Datecompleted)
INTO tbl_Users_non_61
FROM
SELECT tbl_Users.UserID
, tbl_Users.RegistrationType
, tbl_Users.Datecompleted
FROM tbl_Users;
END
GO
Resulting error:
Msg 102, Level 15, State 1, Procedure Make_WEEKLY_SUMMARY, Line 5
Incorrect syntax near ‘,’.**
Since you just want to insert records into one table from another, there is a cleaner syntax:
To answer your question though, you do not need the
( )around your first select, but you DO need them around your sub select, then you need to alias the sub-query you are referencing with theFROM: