You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在ADF中用变量/参数替换FetchXML中的固定日期

在Azure Data Factory中动态替换FetchXML的固定日期值

方案1:使用管道参数

假设你已创建两个字符串类型的管道参数:StartDate和EndDate,值格式为yyyy-MM-ddTHH:mm:ssZ(例如2020-10-20T00:00:00Z)。替换后的动态表达式如下:

@concat(
    '<fetch mapping="logical" version="1.0">',
    '  <entity name="account">',
    '    <attribute name="createdon" />',
    '    <filter>',
    '      <condition attribute="createdon" operator="ge" value="', parameters('StartDate'), '" />',
    '      <condition attribute="createdon" operator="le" value="', parameters('EndDate'), '" />',
    '    </filter>',
    '  </entity>',
    '</fetch>'
)

如果参数是DateTime类型,需要先转换为字符串格式:

@concat(
    '<fetch mapping="logical" version="1.0">',
    '  <entity name="account">',
    '    <attribute name="createdon" />',
    '    <filter>',
    '      <condition attribute="createdon" operator="ge" value="', formatDateTime(parameters('StartDate'), 'yyyy-MM-ddTHH:mm:ssZ'), '" />',
    '      <condition attribute="createdon" operator="le" value="', formatDateTime(parameters('EndDate'), 'yyyy-MM-ddTHH:mm:ssZ'), '" />',
    '    </filter>',
    '  </entity>',
    '</fetch>'
)

方案2:使用管道变量

若使用管道变量,先定义var_StartDate和var_EndDate两个字符串变量(格式同上述要求),动态表达式写法:

@concat(
    '<fetch mapping="logical" version="1.0">',
    '  <entity name="account">',
    '    <attribute name="createdon" />',
    '    <filter>',
    '      <condition attribute="createdon" operator="ge" value="', variables('var_StartDate'), '" />',
    '      <condition attribute="createdon" operator="le" value="', variables('var_EndDate'), '" />',
    '    </filter>',
    '  </entity>',
    '</fetch>'
)

方案3:动态生成当日日期范围

如果需要自动获取当天的0点到23:59:59作为过滤条件,可直接使用ADF的日期函数:

@concat(
    '<fetch mapping="logical" version="1.0">',
    '  <entity name="account">',
    '    <attribute name="createdon" />',
    '    <filter>',
    '      <condition attribute="createdon" operator="ge" value="', formatDateTime(utcNow(), 'yyyy-MM-ddT00:00:00Z'), '" />',
    '      <condition attribute="createdon" operator="le" value="', formatDateTime(utcNow(), 'yyyy-MM-ddT23:59:59Z'), '" />',
    '    </filter>',
    '  </entity>',
    '</fetch>'
)

注意事项

  • 确保日期格式严格符合ISO 8601 UTC标准,否则FetchXML会执行失败
  • 拼接字符串时使用单引号包裹XML片段,避免双引号冲突
  • 若涉及时区转换,可使用convertTimeZone函数调整日期后再格式化

内容的提问来源于stack exchange,提问作者abs786123

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.08 14:30:16