【问题标题】:SQL Stored Procedure unknown ErrorSQL 存储过程未知错误
【发布时间】:2014-08-23 12:24:57
【问题描述】:

我正在编写一个将在 Access 中调用的 SQL 存储过程。我的 sp 将传递四个数据字段(BatchID、InstrumentName、FileName、QueueId)。然后它将一条记录插入到表中(tblinstrumentInterfaceLog)。到目前为止,这是我的代码:

CREATE PROCEDURE upInsertToInstrumentInterfaceLog @BatchID int, @InstrumentName nvarchar(60), @FileName nvarchar(60), @QueueID int 
INSERT INTO tblInstrumentinterfaceLog (batchId,Instrumentname,"Filename",QueueID,DateOfBatch,folder)
   VALUES (@batchid,@InstrumentName,@FileName,@QueueID,@getdate(),'New')
GO

我相信我的格式正确,但我收到两个错误:

Msg 156, Level 15, State 1, Procedure upInsertToInstrumentInterfaceLog, Line 2
Incorrect syntax near the keyword 'INSERT'.

Msg 137, Level 15, State 2, Procedure upInsertToInstrumentInterfaceLog, Line 3
Must declare the scalar variable "@QueueID".

为了确保可能没有数据类型问题,我查看了 tblInstrumentInterfaceLog 的架构,这似乎与我初始化每个的方式相匹配。

如果他们发现此存储过程存在问题,可以告诉我

【问题讨论】:

    标签: mysql sql sql-server stored-procedures


    【解决方案1】:

    在参数声明之后你需要一个 AS 并且你的 @getdate() 命令只是 getdate()

    CREATE PROCEDURE upInsertToInstrumentInterfaceLog 
    @BatchID int, @InstrumentName nvarchar(60), @FileName nvarchar(60), @QueueID int 
    
    AS
    BEGIN
    
    INSERT INTO tblInstrumentinterfaceLog (batchId,Instrumentname,"Filename",QueueID,DateOfBatch,folder)
       VALUES (@batchid,@InstrumentName,@FileName,@QueueID,
               getdate(),'New')
    
    END
    
    GO
    

    【讨论】:

      【解决方案2】:

      你忘了AS

      CREATE PROCEDURE upInsertToInstrumentInterfaceLog @BatchID int, @InstrumentName nvarchar(60),
      @FileName nvarchar(60), @QueueID int
      AS
      INSERT INTO tblInstrumentinterfaceLog (batchId,Instrumentname,"Filename",QueueID,DateOfBatch,folder)
         VALUES (@batchid,@InstrumentName,@FileName,@QueueID,@getdate(),'New')
      GO
      

      【讨论】:

      • 哦,当然!我只关注插入语句语法
      猜你喜欢
      • 1970-01-01
      • 2021-10-18
      • 1970-01-01
      • 2015-06-14
      • 2015-11-19
      • 2014-01-22
      • 1970-01-01
      • 1970-01-01
      • 2013-05-17
      相关资源
      最近更新 更多