Hi Vivek!
Thanks for reaching out!
What you can do is add query parameters to the APIM with the following steps:
- Find the endpoint in your APIM
- Click the 'pencil' to edit
- Select the 'query' tab
- Add the query parameters, for example "start-date" and "end-date"
After you did this you can send the query parameters through APIM which are ready for the LA to be consumed.
You can reference the query parameters in your Logic App using the codes below and use them as desired in your SELECT statement:
However, you say you want optional parameters referenced in your SELECT statement, which makes it not able to add it directly.
What I like to do is the following:
- Add an Array variable in your Logic App called 'sqlQuery'
- Add a condition with the following code for the start date, checking if it not is equal to null coalesce(triggerOutputs()?['queries']?['start-date'])
- Add a append-to-array action in the true part of the condition containing the following for the start date StartDateTime >= '@{triggerOutputs()['queries']['start-date']}'
- Add another condition for the end date with the following code, again not being equal to null coalesce(triggerOutputs()?['queries']?['end-date'])
- Add another append-to-array with the following code for the end date StartDateTime <= '@{triggerOutputs()['queries']['end-date']}'
- Add the following code which basically checks if there were any statements added to the sqlQuery variable, and if so concat 'WHERE' to start the where-clause and afterwards join the sqlQuery array with ' AND ' to make sure the where-statements for a valid query if(greater(length(variables('sqlQuery')),0),concat('WHERE ',join(variables('sqlQuery'),' AND ')),'')
Also, find the image below for your reference: