Forum Discussion

jmiridium's avatar
jmiridium
Helper IV
9 years ago
Solved

Same Query Across Multiple Servers

I would like to run the following query on multiple servers and enter the results into one table:   SELECT             SERVERPROPERTY('MachineName') AS [ServerName],             SERVERPROPERTY('S...
  • prathy's avatar
    9 years ago

    Hi,

     

    What you need is a query with all server names you want to get server information for. Then you can create a function in Power Query / Power BI query editor like below

     

    let
        Source = (ServerName as any) => let
            Source = Sql.Database(ServerName, "master", [Query="SELECT#(lf)            SERVERPROPERTY('MachineName') AS [ServerName],#(lf)            SERVERPROPERTY('ServerName') AS [ServerInstanceName],#(lf)            SERVERPROPERTY('InstanceName') AS [Instance],#(lf)            SERVERPROPERTY('Edition') AS [Edition],#(lf)            SERVERPROPERTY('ProductVersion') AS [ProductVersion],#(lf)            Left(@@Version, Charindex('-', @@version) - 2) As VersionName"])
        in
            Source
    in
        Source

     

    Above query is using ServerName parameter. Once you have the function, you can invoke function in query editor, chosse servername column as the value for function. which will enable you run that function for all servers at the same time.

     

     

    Hope that helps!

     

    Thanks,

    Prathy