1

I have 2 SQL queries. The 1st query gives the name of the report, none of rows of the result. Its kind of like the header for the flat file output. The 2nd query gives the actual results. (Sno, Owner, product details)

How do I merge these 2 queries and have the output of these in a flat file?

The merge of the 2 queries is suppose to be done using SSIS and the output of the 2 queries is to be in the flat file .

Please let me know if you need more details.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Sinred
  • 13
  • 4
  • `select from t1 union all select from t2` – juergen d Aug 28 '17 at 20:24
  • set up a batch file - launch the first query - piping results to a file, then launch the second piping results to the same file...? or use a report writing system :) – Randy Aug 28 '17 at 20:54

2 Answers2

0

select * from table_1 union select * from table_2;

While union is the best option to go through this for better understanding. What is the difference between JOIN and UNION?

Miroslav Glamuzina
  • 4,472
  • 2
  • 19
  • 33
Shaamuji
  • 37
  • 12
0

If you want to have all the data combined into a single column, you can use a UNION.

    SELECT * FROM t1 
    UNION
    SELECT * FROM t2

On the other hand, if the report name is contained in both query results, you can combine the columns using JOIN.

    SELECT * 
    FROM t1
    INNER JOIN t2 on t1.report_name = t2.report_name
ikaikastine
  • 601
  • 8
  • 22
  • The 2 tables result is not same.. the 1st table result: 'Name of the report: total number of rows".. The 2nd table result has "Sno, Owner, Product Details". I believe union doesn't work if the 2 tables outputs are completely different. – Sinred Aug 30 '17 at 14:12
  • Correct a union would not work in that instance. What is the relationship between the two tables? If they are unrelated and just need to be merged, you may want to try using Insert. – ikaikastine Aug 30 '17 at 15:12