SQL存储过程未知错误

时间:2014-07-02 15:55:41

标签: mysql sql sql-server stored-procedures

我正在编写一个将在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的模式,这似乎与我初始化每个模式的方式相匹配。

enter image description here

有人可以告诉我他们是否发现此存储过程存在问题

2 个答案:

答案 0 :(得分:1)

您忘记了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

答案 1 :(得分: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