9

How can we pass parameter to SQL query in Azure data factory ...

ex: Select * from xyz_tbl where date between @date1 and @date2

if I use stored procedure with output @date1 and @date2 parameter, how can I pass these parameter to sql query.

1 Answer 1

16

Which version of Azure DataFactory are you using, v1 ir v2?

If v2 is an option for you, you could achieve this by using Lookup activity that queries the database to get your dynamic properties and then referencing that activity's output in your sql query like so:

select * from from xyz_tbl 
where date between @{activity('LookupActivity').output.date1} 
and @{activity('LookupActivity').output.date2}

Here's a more detailed msdn tutorial for the Lookup activity: https://learn.microsoft.com/en-us/azure/data-factory/control-flow-lookup-activity

Sign up to request clarification or add additional context in comments.

3 Comments

Just in case someone is working with a query like where DATETIME_MODIF >= '@{activity('MAX_DT_MODIF').Output.firstRow.MAXDT}' I had to add single quotes. Thanks for the info Antonia!
Unfortunately, this runs dynamic sql instead of using sql parameter markers - any thoughts on how to get it to use parameter markers?
using the @{activity...} syntax is far better than Microsoft and other recommendations of using @concat(...) - especially when trying to insert dynamic (incremental load) dates into a large SQL script. Plus, it avoids the need to find and replace all single quotes with triple quotes that are requied with @concat()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.