How to pass a dynamic parameter as SQL query in for SQL dataset in Azure Data Flow?

Dimeji Olayinka 37 Reputation points
2022-03-30T21:08:50.19+00:00

I am trying to run dynamic queries with a parameter in Azure Data Flow but I continue to get the "Column operands are not allowed in literal expressions" error. The parameter value is "SELECT * FROM Table WHERE Column in ('D1234','D1234','D1234','D8585','D6565','D7777','D4949','D2066','D2259','D5432')". I have tried all the ways to enter this parameter value, "{$parameter1}", {$parameter1}, $parameter1, ($parameter1) and I still continue to get the frustrating error. I have looked at all the documentation and forums relating to this issue but all of them continue to suggest the same ways I have tried to enter the value and none of it works. Any assistance would be greatly appreciated. 188561-screenshot-2022-03-30-165028.png

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
9,651 questions
0 comments No comments
{count} vote

Accepted answer
  1. AnnuKumari-MSFT 31,151 Reputation points Microsoft Employee
    2022-04-05T13:56:41.77+00:00

    Hi @Dimeji Olayinka ,
    Apologies for the delay in response.

    Thanks for providing the detailed screenshots of the entire workflow. I tried to reproduce your scenario by creating a set variable activity which contains SQL query and trying to pass it to data flow as an expression in the parameter.

    When I manually passed the SQL query as the parameter while checking the data preview in data flow, I was able to get the desired result. However, I faced the same issue when I executed the pipeline even after checking the expression checkbox while calling dataflow in the pipeline. I concluded that the output of set variable activity is not getting passed correctly, which led me to explicitly pass the double quotes by concatenating with the output of set variable activity.

    In the parameter value of data flow activity, kindly use the following code to concat double quotes explicitly over the variable :

    @concat('"',string(variables('S')),'"')  
    

    Here is the video you can refer to:

    190231-debugerror.gif

    For the Authorization error, Could you please check to ensure that you have the Storage Blob Data Contributor role assigned to you on the storage account? If the roles are set correctly, then it might seem to be an intermittent issue . However, I am checking on this with internal team . I will let you know once I hear back from them .

    Hope this will help. Please let us know if any further queries.

    ------------------------------

    • Please don't forget to click on 130616-image.png or upvote 130671-image.png button whenever the information provided helps you.
      Original posters help the community find answers faster by identifying the correct answer. Here is how
    • Want a reminder to come back and check responses? Here is how to subscribe to a notification
    • If you are interested in joining the VM program and help shape the future of Q&A: Here is how you can be part of Q&A Volunteer Moderators

3 additional answers

Sort by: Most helpful
  1. Maciszewski, Bart M 1 Reputation point
    2022-09-07T22:28:29.567+00:00

    All, I noticed something strange while trying to use parameters in SQL source queries:

    The parameters are not parsed when you use the query code editor functionality:
    238852-image.png

    Instead you need to click on the add dynamic code content for the parameters to be parsed properly...

    238756-image.png

    This took me a while to figure out. Is this a bug or intended functionality?


  2. AnnuKumari-MSFT 31,151 Reputation points Microsoft Employee
    2022-04-01T07:02:27.713+00:00

    Hi @Dimeji Olayinka ,

    Thankyou for using Microsoft Q&A platform and posting your query.

    As per your query, it looks like you want to parameterize query your query in the Source transformation of mapping data flow. Here is what you need to do:

    • Create parameters in the data flow specifying the correct data type

    188986-image.png

    • In the query option of source transformation , open expression builder and write your query inside double quotes and specify the parameters using string interpolation {$parameter} . For example: "select * from [{$schemaName}].[{$tableName}] where dataTypeName = '{$dataTypeName}'"

    189063-image.png

    • Ouptut in data preview

    189006-image.png

    For more details, please refer the following links:
    https://learn.microsoft.com/en-us/azure/data-factory/concepts-data-flow-expression-builder#parameters
    https://learn.microsoft.com/en-us/azure/data-factory/parameters-data-flow#passing-in-a-column-name-as-a-parameter
    https://learn.microsoft.com/en-us/answers/questions/439041/error-column-operands-are-not-allowed-in-literal-e.html

    If the suggested response helped you, Please do consider clicking Accept Answer and take survey for the same as accepted answers help community as well. If you have any further query do let us know.

    1 person found this answer helpful.

  3. Dimeji Olayinka 37 Reputation points
    2022-04-04T15:19:48.84+00:00

    NOT AN ANSWER. THIS IS A DETAILED QUESTION WITH SCREENSHOTS
    Hello @AnnuKumari-MSFT It is not a dynamic parameter if I am giving it a default value. My use case is actually dynamic as I am building the query through the Aggregate and Derive Column schema modifiers and then assigning it to the parameter. I have tried entering the parameter with brackets and quotes around those brackets {$parameter1} "{$parameter1}" as well.
    189670-pt1.png189811-pt2.png189748-pt3.png189749-pt4.png

    189821-pt5.png

    Furthermore, My goal is to keep all this work within 1 dataflow. In the event that the above is not possible I have tried splitting this into a 3 activity pipeline where the 1st activity is a dataflow that outputs my dynamic SQL query, the second is assigning the output to a variable, and the third is a dataflow assigning that variable to the parameter that is used as the SQL query. But when I get to the 3rd activity I get this "Expression cannot be parsed error" which I do not understand. The parameter value is a string it should be easy to parsed. The screenshots are below.
    189786-pta.png189831-ptb.png189812-ptc.png189841-ptd.png