-1

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」付近の構文が正しくありません。
メッセージ 137、レベル 15、状態 2、プロシージャ Grant_Append、行 65
変数 '@1600' を宣言する必要があります

4

2 に答える 2

4

GRANTは予約済みキーワードです。エラーを避けるために区切る必要があります。

INSERT INTO dbo.[Grant] ....

パラメータにもタイプミスがあります。

        @1600,
        @1602,
        @1603,
        @1608,
        @1612,

いつあるべきか

        @L1600,
        @L1602,
        @L1603,
        @L1608,
        @L1612,
于 2013-03-12T16:29:11.700 に答える
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;
于 2013-03-12T16:47:27.137 に答える