Forum Discussion

schdef's avatar
schdef
Frequent Visitor
9 years ago
Solved

Parameterized SQL Query with query folding

I have a table loaded to my data model containing IDs. I want use these IDs to filter another query connecting to a SQL table. I tried to merge the SQL query with the ID table but then the query does...
  • Anonymous's avatar
    Anonymous
    9 years ago

    Hi schdef,

     

    You can tansfrom your data to text, then use it into sql query.

     

    Sample: Convert region records to text.

     

    let
        Source=data,
        Region = "'"&Text.Combine(List.Distinct(Source[Region]),"','")&"'"
    in
        Region

     

     

    Insert into sql query:

     

    let
    Source = Sql.Database("xxxxx", "xxxxx", [Query="SELECT * FROM Sales WHERE Region In ("&Region&")"])
    in
    Source

     

     

    Regards,

    Xiaoxin Sheng