Using separate queries makes this a LOT more difficult than necessary. For it to work, you essentially need to pivot or transpose the rows of each query into separate columns. Not an easy task, unless all of your queries are guaranteed to contain the exact same dates, in the same order (unlikely).
If you have a fixed number of events, it is much simpler to use a single database query to generate all of counts. Use a CASE
statements to build the counts based on the "Events" value:
(Note: This cannot be done inside a QoQ. They do not support CASE
).
SELECT STR_TO_DATE(date_format(Timedetail,'%m-%d-%Y'),'%m-%d-%Y') as TheDate
, SUM( CASE WHEN EVENTS = 'First' THEN 1 ELSE 0 END ) AS FirstConn
, SUM( CASE WHEN EVENTS = 'Second' THEN 1 ELSE 0 END ) AS SecondConn
, SUM( CASE WHEN EVENTS = 'Third' THEN 1 ELSE 0 END ) AS ThirdConn
FROM YourTableName
WHERE Timedetail >= <cfqueryparam value="#form.startdate#" cfsqltype="cf_sql_date">
AND Timedetail < <cfqueryparam value="#dateAdd('d', 1,form.enddate)#" cfsqltype="cf_sql_date">
GROUP BY STR_TO_DATE(date_format(Timedetail,'%m-%d-%Y'),'%m-%d-%Y')
Once you have all the results in a single query, you can do the rest on your own. As Adam mentioned, just do a search on ColdFusion query to csv. There are tons of examples you can follow, as well as a number of pre-built functions for converting queries to CSV: