Two queries and one csv file (1 Viewer)

WillSmiTh

New member
Local time
Today, 09:58
Joined
May 14, 2013
Messages
2
Hi,
I have two queries and i want to create one csv file that contains the result of these two queries, How can i do that?
First query has only 1 record and 5 columns, the second query has many records with 12 columns. Only the columns names of the second query must be included in the csv file. I'm newbie in Vb, plz help guys!
Thanks in advance !
 

DJkarl

Registered User.
Local time
Today, 11:58
Joined
Mar 16, 2007
Messages
1,028
First you should really get both queries to have the same number of columns, otherwise how can you relate the data together?

If they have the same number of columns, in the same order, you can join them together with a UNION statement.

create a new query

SELECT * FROM query1

UNION ALL

SELECT * FROM query2

Export your new query to CSV and you're done.
 

WillSmiTh

New member
Local time
Today, 09:58
Joined
May 14, 2013
Messages
2
Hi DJkarl,
My first query contains informations about second query like number of records, year , sum of column values,..So they dont have same columns number.
My final csv file should look like this (see attached image plz).
 

Attachments

  • 2013-05-14_13h58_31.png
    2013-05-14_13h58_31.png
    57.3 KB · Views: 75

DJkarl

Registered User.
Local time
Today, 11:58
Joined
Mar 16, 2007
Messages
1,028
You will likely need to use the Open command with the Append option.

This is just a very quick sample.
Code:
Open "C:\Temp\Yourfile.csv" for Append as #1
    Print #1, CommaDelimitedStringHere
Close#1
 

Users who are viewing this thread

Top Bottom