azure data factory: use variables in query

↘锁芯ラ 提交于 2020-06-29 04:29:08

问题


I have created a copy activity that copies data from an on premise database to a Azure SQL Database. I need to modify dynamiccaly the query so it take a range of date, so I create two variables:
- inidate
- enddate
that I want to use inside the where clause, but I don't know how to reference the variables. I tried this but it doesn't work:

"SELECT * FROM tableOnPrem WHERE dateOnPrem BETWEEN '@variable('inidate')' AND '@variable('enddate')'

please help. meny thanks


回答1:


In a Pipeline (like for Copy activity), you will need to build the query string dynamically using the Pipeline Expression Language (PEL). The best way to do this is to use the concat function to piece together the query:

@concat('SELECT * FROM tableOnPrem WHERE dateOnPrem BETWEEN ''',variables('inidate'),''' AND ''',variables('enddate'),'''')

This can get complex rather quickly, so you'll need to pay extra attention to commas, parentheses, ''' and ''''.

Note that the '@' symbol only appears once, at the beginning of the expression. Also, to reference a pipeline variable you are calling the "variables function.



来源:https://stackoverflow.com/questions/62213623/azure-data-factory-use-variables-in-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!