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
相关产品推荐
相关产品推荐

