How to export data from a SQL database into a CSV file and add some new data?
September 8, 2010 1:47 PM Subscribe
How can I export data from a SQL database into a CSV file and add a new column at the same time?
posted by jfricke to computers & internet (8 answers total) 1 user marked this as a favorite
This might be a really easy question for someone with SQL experience. I have none so far. So please help me out.
I want to do three things. First, I would like to have a query which lists all the records that match a specific ZIP Code. As far as I understood this should look something like this:
SELECT FirstName, LastName, Street, Place, ZIP, Email
WHERE ZIP LIKE '2%'
Second, I want to write the results into a csv file. The rows must be separated by comma. And finally, I want the query to write a new column for each record called 'station' which will have the same value for all records.
The CSV should look something like this in the end:
Firstname, Lastname, Street, Place, ZIP, Email, Station
Thomas, Mueller, Main Street 2, Munich, 80938, firstname.lastname@example.org, Munich
Fritz, Mueller, Second Street 7, Erding, 87498, email@example.com, Munich
How can I do this with SQL?