我已经构建了以下存储过程。它似乎工作得很好,而且数据也在表中。但是,可编程逻辑控制器无法选择@QueryComplete值为1。这里的问题可能是什么。唯一的错误警告如下:
形式参数@QueryComplete未声明为输出.
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[SP_Genealogy_WIP]
-- Add the parameters for the stored procedure here
@engine_number as nvarchar(50),
@line_id as int,
@stage_id as int,
@activity_id as int,
@activity_value as nvarchar(50),
@quantity as int,
@status as int,
@plc_YYYY as int,
@plc_MM as int,
@plc_DD as int,
@plc_HR as int,
@plc_MIN as int,
@plc_SEC as int,
-- [Sending Output]
@QueryComplete int OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from;
-- interfering with SELECT statements.
--SET NOCOUNT ON;
Declare @plc_timestamp nvarchar(20);
SET @plc_timestamp = cast(@plc_YYYY as nvarchar(4)) + '-' + Cast(@plc_MM as nvarchar(2)) + '-' + Cast(@plc_DD as nvarchar(2)) + ' ' + Cast(@plc_HR as nvarchar(2)) + ':' + Cast(@plc_MIN as nvarchar(2)) + ':' + Cast(@plc_SEC as nvarchar(2));
SELECT @plc_timestamp as 'PLC TIMESTAMP';
-- Building the Create Statement
BEGIN TRY
INSERT INTO [dbo].[Genealogy_WIP] (
[engine_number]
,[line_id]
,[stage_id]
,[activity_id]
,[activity_value]
,[quantity]
,[status]
,[plc_timestamp]
) VALUES (
@engine_number,
@line_id,
@stage_id,
@activity_id,
@activity_value,
@quantity,
@status,
CAST(@plc_timestamp as datetime)
);
SET @QueryComplete = 1;
SELECT @QueryComplete OUTPUT;
SELECT ' Inserted successfully.' AS Response;
END TRY
BEGIN CATCH
-- statement to handle errors
IF ERROR_NUMBER()=2627
SELECT '[Error]-You cannot insert this value into the table as there is a primary key violation (in the Line ID field) or one of the inputs is incorrect.' AS Response
END CATCH
END发布于 2022-05-10 13:41:31
当必须从参数输出值时,必须
若要执行具有输出中的参数的过程,必须:
例子:
DDL:
CREATE PROC P @DT DATETIME2 OUTPUT
AS
SET @DT = SYSUTCDATETIME();
GO主管:
DECLARE @DATETIME2_READ DATETIME2;
EXEC P @DATETIME2_READ OUTPUT;
SELECT @DATETIME2_READ;https://stackoverflow.com/questions/72185778
复制相似问题