Reputation: 511
I want to use a query in a copy job for my source in an Azure Data Factory pipeline together with a date function - here is the dummy query:
SELECT * FROM public.report_campaign_leaflet WHERE day="{today - 1d}"
I´ve found some documentation about dynamic content and some other stuff but no information on how to use date functions directly in a sql query.
Maybe someone has a hint for me?
Thanks & best, Michael
Upvotes: 2
Views: 4702
Reputation: 171
I had the same issue I have sorted it out via the following method:
@formatDateTime('2022-01-01 00:00:00', 'yyyy-MM-dd HH:mm:ss')
Write the following Code to the pipeline expression builder:
@{concat('select * from Table where Column1=''','A',''' AND TO_CHAR(Date, ''', 'YYYY-MM-DD HH24:MI:SS',''') >= ''', variables('X'),'''')}
This will do the trick!
Upvotes: 0
Reputation: 21
You need to replace the double quote ("
) with two single quotes (''
):
@concat('SELECT * FROM public.report_campaign_leaflet WHERE day=','''',formatDateTime(adddays(utcnow(),-1), 'yyyy-MM-dd'),'''')
Upvotes: 2
Reputation: 1138
Here is the possible solution for your problem.
In your copy activity, at the source side, you choose query in Use Query option, and then in the query box you write an expression
Here is the expression @concat('SELECT * FROM public.report_campaign_leaflet WHERE day=','"',formatDateTime(adddays(utcnow(),-1), 'yyyy-MM-dd'),'"')
formatDateTime function will just format the output of addDays(utcnow(),-1) into yyyy-MM-dd format
Again, you can have a parameter in your pipeline processDate for example, and to set this value from expression in trigger definition, and then just to call that parameter in the query. (suggestion)
Upvotes: 4