没有得到存储过程的Ouytput

时间:2018-01-15 11:27:15

标签: sql-server tsql stored-procedures dynamic-sql

我没有得到此程序的输出

   ALTER PROC [dbo].[SPTaxRepOutPrtWs]
    @DTS            DATETIME
    ,@DTE           DATETIME
    ,@VTypeStr      VARCHAR(200)
    ,@AcntStr       VARCHAR(200)
    ,@IsSummary     CHAR(1)
AS
BEGIN
DECLARE @nstrSQL                    NVARCHAR(4000)
        ,@nstrSQLPara               NVARCHAR(4000)
        ,@chr13                     CHAR(1)
        ,@StrVtypeCond              NVARCHAR(200)

IF @VTypeStr <> '**+'
BEGIN
    SELECT @VTypeStr = (''''+REPLACE(@VTypeStr,'+',''',''')+'''')
END

SELECT @StrVtypeCond = (CASE WHEN @VTypeStr = '**+' THEN '1=1' ELSE 'A.V_Type IN (' +@VTypeStr+ ')' END)

SELECT @nstrSQLPara = '@DTS DATETIME, @DTE DATETIME, @VTypeStr VARCHAR(200), @AcntStr VARCHAR(200), @IsSummary CHAR(1)'

SELECT @nstrSQL = 
    +'SELECT A.Prt_Ac,ISNULL(B.Descript,'''') AS Descript,A.V_Type,A.V_No,A.Date,A.Tot_Amt,A.Quantity'+@chr13 
    +'FROM Sales A'+@chr13
    +'  LEFT OUTER JOIN Party B ON A.Prt_Ac=B.Prt_Code'+@chr13
    +'WHERE A.Date BETWEEN @DTS AND @DTE'+@chr13
    +'AND '+@StrVtypeCond

EXEC SP_EXECUTESQL @nstrSQL, @nstrSQLPara, @DTS, @DTE, @VTypeStr, @AcntStr, @IsSummary
RETURN  
END

1 个答案:

答案 0 :(得分:0)

正如GarethD在评论中提到的那样,您声明了一个名为CHAR(1)的{​​{1}}变量,该变量永远不会设置为任何值,因此为@chr13

然后,当您将该变量与其他值(其结果也是NULL)连接并将结果分配给NULL时,此变量也变为@nstrSQL。那么当你将NULL传递给@nstrSQL时,它是一个NULL参数,因此你没有得到任何结果。