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

Azure Data Factory参数拼接查询报错:Synapse跨模式复制语法错误

问题解决:Synapse Copy Activity SQL拼接语法错误

错误原因

报错提示语法错误在03附近,核心问题是日期值没有用单引号包裹。SQL中日期/字符串类型的条件值必须用单引号括起来,你当前拼接的SQL会变成类似:

select * from DW_GL.table_name where updated_on >2024-03-01 and updated_on <=2024-03-02

这种写法会被SQL解析器当成数值运算(2024减03减01),自然触发语法错误。

修正后的表达式

把日期值用单引号包裹,修改concat表达式如下:

@concat('select * from DW_GL.',pipeline().parameters.p_param_input_table,' where updated_on >''',activity('Old_Lookup1').output.firstRow.date_value,''' and updated_on <=''',activity('Old_Lookup1').output.firstRow.date_value_new,'''')

注:在ARM模板表达式里,单引号需要用两个单引号转义,这样最终生成的SQL里会保留单个单引号。

验证方法

可以先在Pipeline的Debug模式下,查看Copy Activity生成的实际SQL语句,确认日期值是否被正确包裹,比如应该是:

select * from DW_GL.table_name where updated_on >'2024-03-01' and updated_on <='2024-03-02'

额外建议

如果date_value和date_value_new是DateTime类型而非字符串,建议用formatDateTime函数统一格式,避免日期格式不兼容问题:

@concat('select * from DW_GL.',pipeline().parameters.p_param_input_table,' where updated_on >''',formatDateTime(activity('Old_Lookup1').output.firstRow.date_value,'yyyy-MM-dd'),''' and updated_on <=''',formatDateTime(activity('Old_Lookup1').output.firstRow.date_value_new,'yyyy-MM-dd'),'''')

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.05 16:10:30