我使用MSSQL-server 2012。
我创建了存储过程:
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
在此行的存储过程中:
dbo.ReportTrafficDepartment(siteNum, dateReport, siteName, prog1, progLayout1, prog2, progLayout2, isLOZ, start, end, time, Prog1ToProg2Check, comment)
我对这个词有误:
end
错误的文字是:
Msg 156,Level 15,State 1,Procedure SaveEcxelReport,Line 28
关键字' end'附近的语法不正确。
知道为什么我上面会出现错误以及如何修复它?
答案 0 :(得分:2)
end
是一个SQL关键字。因此,使用括号包装列名称,类似于此[end]
。开始和时间也属于同一个家庭。用括号括起列名将表明这不是关键字。
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
答案 1 :(得分:1)
为时间和结尾添加[]括号,如下所示
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 :(得分:0)
我已经开始用方括号包裹所有列和标签。它会给你带来很多麻烦。