我在SQL Server中创建了一个存储过程,但是我收到了这个错误,但是我不确定它是什么意思。
以下是程序:
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[Grant_Append]
-- Add the parameters for the stored procedure here
(@GrantNumber AS VARCHAR(50),
@GrantName AS VARCHAR(100),
@ProjectCode AS VARCHAR(50),
@LOCID AS INT,
@Comments AS VARCHAR(100),
@Provider AS VARCHAR(100),
@ISAT AS NCHAR(10),
@TypeID AS INT,
@Slots AS FLOAT,
@Patients AS FLOAT,
@FundingMethod AS VARCHAR(50),
@L1600 AS MONEY,
@L1602 AS MONEY,
@L1603 AS MONEY,
@L1608 AS MONEY,
@L1612 AS MONEY,
@ADAAFunding AS MONEY,
@ProgramBudget AS MONEY,
@Jurisdiction AS INT,
@VersionType AS VARCHAR(20),
@VersionNum AS INT)
AS BEGIN
INSERT INTO dbo.Grant
(GrantNumber,
GrantName,
ProjectCode,
LOCID,
Comments,
Provider,
ISAT,
TypeID,
Slots,
Patients,
FundingMethod,
[1600],
[1602],
[1603],
[1608],
[1612],
ADAAFunding,
ProgramBudget,
Jurisdiction,
VersionType,
VersionNum,
SubmitDate)
-- Insert statements for procedure here
SELECT @GrantNumber,
@GrantName,
@ProjectCode,
@LOCID,
@Comments,
@Provider,
@ISAT,
@TypeID,
@Slots,
@Patients,
@FundingMethod,
@1600,
@1602,
@1603,
@1608,
@1612,
@ADAAFunding,
@ProgramBudget,
@Jurisdiction,
@VersionType,
@VersionNum,
getdate()
END
这些是错误:
消息156,级别15,状态1,程序Grant_Append,第30行 关键字'Grant'附近的语法不正确。
Msg 137,Level 15,State 2,Procedure Grant_Append,Line 65
必须声明变量'@ 1600'
答案 0 :(得分:4)
GRANT
是保留关键字。它应该被分隔以避免错误,例如
INSERT INTO dbo.[Grant] ....
参数中也存在拼写错误
@1600,
@1602,
@1603,
@1608,
@1612,
什么时候应该
@L1600,
@L1602,
@L1603,
@L1608,
@L1612,
答案 1 :(得分:0)
我建议将您的表名从[Grant](保留关键字)更改为未保留的内容,即[Grants]。另外,我建议不要用数字开始列名。因此,例如,使用描述性的前缀[1600]。我用“费用”作为例子。以下是适合您的代码示例:
-- DROP TABLE dbo.Grants
CREATE TABLE dbo.Grants
(
GrantNumber VARCHAR(50),
GrantName VARCHAR(100),
ProjectCode VARCHAR(50),
LOCID INT,
Comments VARCHAR(100),
Provider VARCHAR(100),
ISAT NCHAR(10),
TypeID INT,
Slots FLOAT,
Patients FLOAT,
FundingMethod VARCHAR(50),
Fee1600 MONEY,
Fee1602 MONEY,
Fee1603 MONEY,
Fee1608 MONEY,
Fee1612 MONEY,
ADAAFunding MONEY,
ProgramBudget MONEY,
Jurisdiction INT,
VersionType VARCHAR(20),
VersionNum INT,
SubmitDate DATETIME
);
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[GrantsInsert_sp]
-- Add the parameters for the stored procedure here
(@GrantNumber AS VARCHAR(50),
@GrantName AS VARCHAR(100),
@ProjectCode AS VARCHAR(50),
@LOCID AS INT,
@Comments AS VARCHAR(100),
@Provider AS VARCHAR(100),
@ISAT AS NCHAR(10),
@TypeID AS INT,
@Slots AS FLOAT,
@Patients AS FLOAT,
@FundingMethod AS VARCHAR(50),
@Fee1600 AS MONEY,
@Fee1602 AS MONEY,
@Fee1603 AS MONEY,
@Fee1608 AS MONEY,
@Fee1612 AS MONEY,
@ADAAFunding AS MONEY,
@ProgramBudget AS MONEY,
@Jurisdiction AS INT,
@VersionType AS VARCHAR(20),
@VersionNum AS INT)
AS BEGIN
INSERT INTO dbo.Grants
(GrantNumber,
GrantName,
ProjectCode,
LOCID,
Comments,
Provider,
ISAT,
TypeID,
Slots,
Patients,
FundingMethod,
Fee1600,
Fee1602,
Fee1603,
Fee1608,
Fee1612,
ADAAFunding,
ProgramBudget,
Jurisdiction,
VersionType,
VersionNum,
SubmitDate)
-- Insert statements for procedure here
SELECT @GrantNumber,
@GrantName,
@ProjectCode,
@LOCID,
@Comments,
@Provider,
@ISAT,
@TypeID,
@Slots,
@Patients,
@FundingMethod,
@Fee1600,
@Fee1602,
@Fee1603,
@Fee1608,
@Fee1612,
@ADAAFunding,
@ProgramBudget,
@Jurisdiction,
@VersionType,
@VersionNum,
GETDATE();
END;
EXECUTE [GrantsInsert_sp] 'abc', 'abc', 'abc', 1, 'abc', 'abc', 'abc', 1, 1, 1, 'abc', 1, 1, 1, 1, 1, 1, 1, 1, 'abc', 1;
SELECT * FROM dbo.Grants;