Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 通过批处理文件使用存储过程的SQLCMD-获取输出参数_Sql Server_Batch File_Stored Procedures_Parameter Passing_Sqlcmd - Fatal编程技术网

Sql server 通过批处理文件使用存储过程的SQLCMD-获取输出参数

Sql server 通过批处理文件使用存储过程的SQLCMD-获取输出参数,sql-server,batch-file,stored-procedures,parameter-passing,sqlcmd,Sql Server,Batch File,Stored Procedures,Parameter Passing,Sqlcmd,我试图通过批处理文件从使用sqlcmd执行的存储过程中获取输出参数。详情: 我正在SQL Server中执行以下存储过程: SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[uspCalibFail] @pStation_Name NVARCHAR(50), @responseMessage NVARCHAR(250) = '' OUTPUT AS BEGIN SET NOC

我试图通过批处理文件从使用sqlcmd执行的存储过程中获取输出参数。详情:

我正在SQL Server中执行以下存储过程:

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[uspCalibFail]
    @pStation_Name NVARCHAR(50),
    @responseMessage NVARCHAR(250) = '' OUTPUT
AS
BEGIN
    SET NOCOUNT ON

    SELECT [Station], [TLI], [Description]
    FROM CalibData
    WHERE Waiver_expiration_dat < GETDATE()

    IF EXISTS (SELECT TOP 1 SELECT [Station], [TLI], [Description] 
       FROM CalibData
       WHERE Waiver_expiration_dat < GETDATE()  
    BEGIN
        SET @responseMessage = 'Station devices overdue for calibration'
    END
    ELSE
        SET @responseMessage='Station OK'
END
GO
因此,我将select查询作为一个表(这很好),但我没有得到输出参数@responseMessage值。我怎样才能得到它

我使用批处理文件来执行存储过程,我使用 batchfile参数,并将其输入为存储过程输入

要在T-SQL脚本中捕获存储过程输出参数,需要声明一个局部变量,并将其指定为存储过程输出参数值。未经测试的示例代码段:

-Q "DECLARE @vresponse_message nvarchar(250); exec [NewDB].[dbo].[uspCalibData] @pStation_Name=$(station),@presponse_message=@vresponse_message OUTPUT;SELECT @vresponse_message AS vresponse_message;" /v station="%~1" 

所有
SELECT
都已损坏:首先,它们缺少一个
FROM
子句来定义要从哪个表中读取,而
IF EXISTS()
中的
SELECT
是错误的,因为在需要它的地方有两次
SELECT
只需一次….修复了FROM子句,但我认为这与这个问题无关……除非我完全离开了。
-Q "DECLARE @vresponse_message nvarchar(250); exec [NewDB].[dbo].[uspCalibData] @pStation_Name=$(station),@presponse_message=@vresponse_message OUTPUT;SELECT @vresponse_message AS vresponse_message;" /v station="%~1"