Query an SQL database and return the results as CSV output