Wie Sie mehrere Ergebnistabellen von SQL Server Management Studio Express gleichzeitig kopieren?

2909
tarheel

I have a query that spits out multiple result tables and I want to be able to select all of the tables at once, hit copy and then paste them all to one Excel file all at the same time. I would also be ok with exporting, if someone knows how to do that.

Note: I do not want to change the default settings, just want to be able to do this for this one query.

Update: I should have specified in my original question that the column in different tables do not match.

3
Klären Sie einfach, was Sie mit Standardeinstellungen meinen? Siva Charan vor 11 Jahren 0
Ich möchte in der Lage sein, nur die betreffende Abfrage zu verwenden und muss die Lösung nicht als pauschale Lösung verwenden. Mit anderen Worten, ich möchte nicht das Verhalten in Tools> Optionen> Abfrageergebnisse ändern. tarheel vor 11 Jahren 0

1 Antwort auf die Frage

1
techturtle

If all your columns are the same in each sub query, then you can put a UNION ALL between them and they will all append to the same query. The columns all have to be the same names and in the same order for this to work. If they are close but not exact, you can do things like add empty columns to one query so it will match another query. For example, if the first query has Name, Rank and Serial for the results, but the second query only has Name and Serial, you can write it like this:

SELECT Name, Rank, Serial FROM Table_A UNION ALL SELECT Name, '' AS Rank, Serial FROM Table_B 
Ich muss Ihnen Requisiten für eine so gute und nützliche Antwort geben, wenn diese Situation eintritt. Leider haben die Spaltennamen in meiner aktuellen Ausgabe keinen Zusammenhang zwischen den Ergebnistabellen. tarheel vor 11 Jahren 0