首页 > 解决方案 > 如何在 Azure 数据工厂的下一次查找中使用查找活动的结果?

问题描述

我使用 SQL 语句查找“获取客户”:

  Select Count(CustomerId) As 'Row_count' ,Min(sales_amount) as 'Min_Sales' From [sales]. 
  [Customers]

它返回值

   10, 5000

接下来我使用 SQL 语句查找“更新最小销售额”,但出现错误:

    Update Sales_Min_Sales
    SET Row_Count = @activity('Fetch Customers').output.Row_count,
    Min_Sales = @activity('Fetch Customers').output.Min_Sales
    Select 1

即使我将 Lookup 设置为,也会发生相同的错误

   Select @activity('Fetch Fetch Customers').output.Row_count

错误:

 A database operation failed with the following error: 'Must declare the scalar variable 
"@activity".',Source=,''Type=System.Data.SqlClient.SqlException,Message=Must declare the 
scalar variable "@activity".,Source=.Net SqlClient Data 
Provider,SqlErrorNumber=137,Class=15,ErrorCode=-2146232060,State=2,Errors= 
[{Class=15,Number=137,State=2,Message=Must declare the scalar variable "@activity".,},],'

标签: azure-data-factory

解决方案


我的设置和你的差不多。两个查找活动。

在此处输入图像描述

首先查找带来如图所示的最小 ID 和最大 ID

{
    "count": 1,
    "value": [
        {
            "Min": 1,
            "Max": 30118
        }
    ],
    "effectiveIntegrationRuntime": "DefaultIntegrationRuntime (East US)",
    "billingReference": {
        "activityType": "PipelineActivity",
        "billableDuration": [
            {
                "meterType": "AzureIR",
                "duration": 0.016666666666666666,
                "unit": "DIUHours"
            }
        ]
    },
    "durationInQueue": {
        "integrationRuntimeQueue": 22
    }
}

在我的第二次查找中,我使用以下表达式

Update saleslt.customer set somecol=someval where CustomerID=@{activity('Lookup1').output.Value[0]['Min']} 

选择 1 作为虚拟

只是我们必须使用前面提到的索引访问查找输出并将活动输出放在 {} 中。


推荐阅读