Forum Discussion

Believer's avatar
Believer
Advocate IV
3 years ago
Solved

How do I combine custom SQL across databases into a single table?

I have the following code which efficiently concatenates the same table from several servers/databases.  (Thanks again, Anonymous !!)  I added a declaration for some custom SQL.  How do I adapt the "...
  • v-jingzhang's avatar
    3 years ago

    Hi Believer 

     

    Based on my test, you can try the following code. Sql.Database - PowerQuery M

     

    let
        CustomSQL = "SELECT * FROM Table_1 WHERE Provider='a';",
        Table1 = Sql.Database("SQLServer1", "Database1", [Query=CustomSQL]),
        Table2 = Sql.Database("SQLServer2", "Database2", [Query=CustomSQL]),
        Source = Table.Combine({Table1, Table2})
    in
        Source

     

     

    Best Regards,
    Community Support Team _ Jing
    If this post helps, please Accept it as Solution to help other members find it.