Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
    
Just clarify, what you mean default settings? –  Siva Charan Oct 8 '12 at 18:24
    
I want to be able to use this only the query in question, and not have to use the solution as a blanket solution. In other words, I don't wan to change the behaviors in Tools > Options > Query Results. –  tarheel Oct 8 '12 at 18:40
add comment

1 Answer

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
share|improve this answer
    
Have to give you props for such a good and useful answer when that situation comes about. Unfortunately, in my current issue the column names are unrelated between result tables. –  tarheel Oct 8 '12 at 17:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.