为什么在创建存储过程时出错?

时间:2022-05-24 15:26:56

I use MSSQL-server 2012.

我使用MSSQL-server 2012。

I create stored procedure:

我创建的存储过程:

CREATE PROCEDURE [dbo].[SaveEcxelReport]

 @siteNum INT = NULL,
 @dateReport DATETIME = NULL,
 @siteName NVARCHAR = NULL,
 @prog1 INT = NULL,
 @progLayout1 INT = NULL,
 @prog2 INT = NULL,
 @progLayout2 INT = NULL,
 @isLOZ BIT = NULL,
 @start DATETIME = NULL,
 @end DATETIME = NULL,
 @time DATETIME = NULL,
 @Prog1ToProg2Check REAL = NULL,
 @comment NVARCHAR = NULL

AS   
BEGIN
  SET NOCOUNT ON;
  insert into dbo.ReportTrafficDepartment(siteNum, dateReport, siteName, prog1, progLayout1, prog2, progLayout2, isLOZ, start, end, time, Prog1ToProg2Check, comment) 
         values (@siteNum,@dateReport,@siteName,@prog1,@progLayout1, @prog2,@progLayout2,@isLOZ,@start,@end,@time,@Prog1ToProg2Check,@comment) 
END

In stored procedurte in this row:

在本行存储过程中:

dbo.ReportTrafficDepartment(siteNum, dateReport, siteName, prog1, progLayout1, prog2, progLayout2, isLOZ, start, end, time, Prog1ToProg2Check, comment)

I get error on this word:

我在这个词上有错误:

end

The text of the error is:

错误的文本是:

Msg 156, Level 15, State 1, Procedure SaveEcxelReport, Line 28

Msg 156,第15层,状态1,过程SaveEcxelReport,第28行

Incorrect syntax near the keyword 'end'.

在关键字“end”附近的语法错误。

Any idea why I get error above and how to fix it?

你知道我为什么会犯上面的错误吗?

3 个解决方案

#1


2  

end is a SQL keyword. So wrap the column name with brackets, similar to this [end]. start and time also belong to the same family. wrapping column names with brackets will indicate that this is not a keyword.

end是一个SQL关键字。所以用括号括起列名,类似于[结尾]。开始和时间也属于同一个家庭。用括号括起来的列名表示这不是关键字。

CREATE PROCEDURE [dbo].[SaveEcxelReport]

 @siteNum INT = NULL,
 @dateReport DATETIME = NULL,
 @siteName NVARCHAR = NULL,
 @prog1 INT = NULL,
 @progLayout1 INT = NULL,
 @prog2 INT = NULL,
 @progLayout2 INT = NULL,
 @isLOZ BIT = NULL,
 @start DATETIME = NULL,
 @end DATETIME = NULL,
 @time DATETIME = NULL,
 @Prog1ToProg2Check REAL = NULL,
 @comment NVARCHAR = NULL

AS   
BEGIN
  SET NOCOUNT ON;
  insert into dbo.ReportTrafficDepartment(siteNum, dateReport, siteName, prog1, progLayout1, prog2, progLayout2, isLOZ, [start], [end], [time], Prog1ToProg2Check, comment) 
         values (@siteNum,@dateReport,@siteName,@prog1,@progLayout1, @prog2,@progLayout2,@isLOZ,@start,@end,@time,@Prog1ToProg2Check,@comment) 
END

#2


1  

Add [] brackets for both time and end as below

为时间和结尾添加[]括号,如下所示

CREATE PROCEDURE [dbo].[SaveEcxelReport]

     @siteNum INT = NULL,
     @dateReport DATETIME = NULL,
     @siteName NVARCHAR = NULL,
     @prog1 INT = NULL,
     @progLayout1 INT = NULL,
     @prog2 INT = NULL,
     @progLayout2 INT = NULL,
     @isLOZ BIT = NULL,
     @start DATETIME = NULL,
     @end DATETIME = NULL,
     @time DATETIME = NULL,
     @Prog1ToProg2Check REAL = NULL,
     @comment NVARCHAR = NULL

    AS   
    BEGIN
      SET NOCOUNT ON;
      insert into dbo.ReportTrafficDepartment(siteNum, dateReport, siteName, prog1, progLayout1, prog2, progLayout2, isLOZ, start, [end], [time], Prog1ToProg2Check, comment) 
             values (@siteNum,@dateReport,@siteName,@prog1,@progLayout1, @prog2,@progLayout2,@isLOZ,@start,@end,@time,@Prog1ToProg2Check,@comment) 
    END

#3


0  

I've gotten into the practice of wrapping all columns and labels with square brackets. It'll save you a lot of headaches.

我已经习惯了用方括号包装所有列和标签。它会省去你很多麻烦。

#1


2  

end is a SQL keyword. So wrap the column name with brackets, similar to this [end]. start and time also belong to the same family. wrapping column names with brackets will indicate that this is not a keyword.

end是一个SQL关键字。所以用括号括起列名,类似于[结尾]。开始和时间也属于同一个家庭。用括号括起来的列名表示这不是关键字。

CREATE PROCEDURE [dbo].[SaveEcxelReport]

 @siteNum INT = NULL,
 @dateReport DATETIME = NULL,
 @siteName NVARCHAR = NULL,
 @prog1 INT = NULL,
 @progLayout1 INT = NULL,
 @prog2 INT = NULL,
 @progLayout2 INT = NULL,
 @isLOZ BIT = NULL,
 @start DATETIME = NULL,
 @end DATETIME = NULL,
 @time DATETIME = NULL,
 @Prog1ToProg2Check REAL = NULL,
 @comment NVARCHAR = NULL

AS   
BEGIN
  SET NOCOUNT ON;
  insert into dbo.ReportTrafficDepartment(siteNum, dateReport, siteName, prog1, progLayout1, prog2, progLayout2, isLOZ, [start], [end], [time], Prog1ToProg2Check, comment) 
         values (@siteNum,@dateReport,@siteName,@prog1,@progLayout1, @prog2,@progLayout2,@isLOZ,@start,@end,@time,@Prog1ToProg2Check,@comment) 
END

#2


1  

Add [] brackets for both time and end as below

为时间和结尾添加[]括号,如下所示

CREATE PROCEDURE [dbo].[SaveEcxelReport]

     @siteNum INT = NULL,
     @dateReport DATETIME = NULL,
     @siteName NVARCHAR = NULL,
     @prog1 INT = NULL,
     @progLayout1 INT = NULL,
     @prog2 INT = NULL,
     @progLayout2 INT = NULL,
     @isLOZ BIT = NULL,
     @start DATETIME = NULL,
     @end DATETIME = NULL,
     @time DATETIME = NULL,
     @Prog1ToProg2Check REAL = NULL,
     @comment NVARCHAR = NULL

    AS   
    BEGIN
      SET NOCOUNT ON;
      insert into dbo.ReportTrafficDepartment(siteNum, dateReport, siteName, prog1, progLayout1, prog2, progLayout2, isLOZ, start, [end], [time], Prog1ToProg2Check, comment) 
             values (@siteNum,@dateReport,@siteName,@prog1,@progLayout1, @prog2,@progLayout2,@isLOZ,@start,@end,@time,@Prog1ToProg2Check,@comment) 
    END

#3


0  

I've gotten into the practice of wrapping all columns and labels with square brackets. It'll save you a lot of headaches.

我已经习惯了用方括号包装所有列和标签。它会省去你很多麻烦。