简体   繁体   English

Azure 逻辑应用程序:如何将单个 For Each 变量传递到执行存储过程步骤?

[英]Azure Logic App: How do I pass a single For Each variable to an Execute Stored Procedure step?

I am using Azure Logic App to execute a stored procedure that accepts a string input.我正在使用 Azure 逻辑应用程序来执行接受字符串输入的存储过程。

Here is the definition of the stored procedure:下面是存储过程的定义:

ALTER PROCEDURE [ResMgmt].[usp_ExtractReportBlob] 
     (@ReportFileName VARCHAR(255),
      @ReportBlobName VARCHAR(255) OUTPUT)
AS
BEGIN
    DECLARE @SQL VARCHAR(MAX), 
            @ReportSPROCName VARCHAR(MAX);

    SET @ReportSPROCName = (SELECT ReportSPROCName
                            FROM ResMgmt.ReportMetadata
                            WHERE ReportFileName = @ReportFileName);

    SET @SQL = 'EXEC ' + @ReportSPROCName + ';';

    SELECT (@SQL);

    SET @ReportBlobName = '/<azure-storage>/' + @ReportFileName;

    RETURN @ReportBlobName;
END;

The stored procedure ultimately outputs a string that will be used by Logic App, but first thing's first... I cannot get my Attachments Name iterator to be used as an input for the stored procedure.存储过程最终会输出一个将由逻辑应用程序使用的字符串,但首先...我无法将我的Attachments Name迭代器用作存储过程的输入。 The stored procedure accepts parameter ReportFileName , which will be coming from the iterator of the For Each step:存储过程接受参数ReportFileName ,该参数将来自 For Each 步骤的迭代器:

对于每一步

You can see that, in the code view, I am referencing the item() dynamically in the body key of the json structure:您可以看到,在代码视图中,我在json结构的body键中动态引用了item()

逻辑应用代码视图

But I end up with this error in debug:但我最终在调试中遇到了这个错误:

错误

When I run from debug, I get the error above.当我从调试运行时,出现上述错误。 It seems like the json format is correct, so I don't understand why the error is occurring.看起来json格式是正确的,所以我不明白为什么会发生错误。 For example, I can confirm that the correct string value DTG Active Client List Daily.csv is getting passed to the stored procedure key ReportFileName .例如,我可以确认将正确的字符串值DTG Active Client List Daily.csv传递给存储过程键ReportFileName

How do I pass this variable to my stored procedure?如何将此变量传递给我的存储过程?

I figured it out, and it's very simple.我想通了,这很简单。 I decided to switch to Execute a SQL Query step for ease, but it worked under the old method as well.为了方便起见,我决定切换到Execute a SQL Query步骤,但它也适用于旧方法。

I am passing a string variable to my stored procedure.我正在将一个字符串变量传递给我的存储过程。 The json "looks" correct because it's contained within double-ticks (eg " " ). json “看起来”是正确的,因为它包含在双引号中(例如" " )。 But the stored procedure is expecting a string contained within single-ticks (eg ' ' ).但是存储过程需要包含在单个刻度中的字符串(例如' ' )。 I had to manually wrap my variable with the single-ticks.我不得不用单刻度手动包装我的变量。

Like so:像这样:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM