Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

How do I extract data from SQL through a query that unions multiple databases of SQL.

Hello all,

 

I have written a SQL query which I want to extract on powerBI. The query includes UNION of multiple databases.. 

What I tried = " go to GET DATA - Server - AdvanceOptions and inserted my query and click OK." 
It is asking me to give the database name. But query includes multiple databases. 

 

How do I extract data from SQL through a query that unions multiple databases of SQL.db1.PNG

1 ACCEPTED SOLUTION
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @Anonymous ,

You could write the T-SQL which could get data from mutiple databases under SQL Statement.

You can run the query in your Sql Server databsed firstly, if that works successfully, then you could copy it under SQL Statement in power bi desktop.

In addition, you could refer to the query below and modify it based on your scenario.

select * from [server].[database].[schema].[table]
union
select * from [server].[database2].[schema].[table]
union
select * from [server].[database3].[schema].[table]

Hope this can help you.

Best  Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @Anonymous ,

Have you solved the problem?

If you have solved, please always accept the replies making sense as solution to your question so that people who may have the same question can get the solution directly.

If you still need help, free to ask.

Best  Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @Anonymous ,

You could write the T-SQL which could get data from mutiple databases under SQL Statement.

You can run the query in your Sql Server databsed firstly, if that works successfully, then you could copy it under SQL Statement in power bi desktop.

In addition, you could refer to the query below and modify it based on your scenario.

select * from [server].[database].[schema].[table]
union
select * from [server].[database2].[schema].[table]
union
select * from [server].[database3].[schema].[table]

Hope this can help you.

Best  Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.