Combine SQLCMD Outputs In One Window

possibilities 41 Reputation points
2022-02-10T19:36:02.93+00:00

I am using SQLCMD Mode in SSMS v18.9.1. When I run a query across multiple unlinked servers, the results from each server display in their own separate window. I then have to copy each set of results out of my virtual machine into Excel on my actual pc, which is time consuming. I want to know if there is a way to combine the results from each output window in SSMS into one final output so that I can copy all records out into Excel at one time. Thank you!

SQL Server | Other
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. Erland Sommarskog 128.7K Reputation points MVP Volunteer Moderator
    2022-02-10T22:21:49.063+00:00

    You can try this: In the View menu, select Registered Servers. Add the servers you are querying in Local Server Groups, or create a new group and the servers to that group. Then right-click the group and select New Query. This permits you to run queries on all servers in the group at once.

    3 people found this answer helpful.

  2. CathyJi-MSFT 22,401 Reputation points Microsoft External Staff
    2022-02-11T02:48:03.017+00:00

    Hi @possibilities ,

    If the query run on the multiple SQL server instance are same, you can try the method that Erland mentioned. Below is a test in my environment.

    173374-screenshot-2022-02-11-104050.jpg

    If the query run on the multiple SQL server instance are different, you can open a Query windows type “:connect” syntax to multiple instance as below screenshot.

    173248-screenshot-2022-02-11-104457.jpg


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    1 person found this answer helpful.

  3. possibilities 41 Reputation points
    2022-02-11T20:25:01.27+00:00

    Thank you both for your help. I am still not getting the code to work but don't want to waste your time any further.

    0 comments No comments

  4. possibilities 41 Reputation points
    2022-10-21T18:28:15.197+00:00

    I wanted to let all of you know that I did get Linked Server Groups to work. Thanks again for all of your help.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.