title: working with CSV
body: <p>I'm running the following query and  QoQ . Could you tell me how should I proceed for the "Download  CSV" file option? </p>
  
  <pre><code>&lt;!--- QoQ for FIRSTCONN ---&gt;
  
  &lt;cfquery datasource = "XX.XX.X.XX" name="master1"&gt;
       SELECT STR_TO_DATE(date_format(Timedetail,'%m-%d-%Y'),'%m-%d-%Y') as FIRSTCONN
              , COUNT(Timedetail) as FIRSTOccurances
              , EVENTS 
       FROM  MyDatabase
       WHERE EVENTS = "FIRST" 
       GROUP BY FIRSTCONN ;
  &lt;/cfquery&gt; 
  
  &lt;!--- Detail Query ---&gt;
  
  &lt;cfquery dbtype="query" name="detail1"&gt;
      SELECT  *
      FROM master1 
      WHERE FIRSTCONN  &gt;= &lt;cfqueryparam value="#form.startdate#" cfsqltype="cf_sql_varchar"&gt; 
      AND   FIRSTCONN  &lt;  &lt;cfqueryparam value="#dateAdd('d', 1,form.enddate)#" cfsqltype="cf_sql_varchar"&gt;;
  &lt;/cfquery&gt;  
  
  
  &lt;!--- QoQ for SECONDCONN ---&gt;
  
  &lt;cfquery datasource = "XX.XX.X.XX" name="master2"&gt;
      SELECT STR_TO_DATE(date_format(Timedetail,'%m-%d-%Y'),'%m-%d-%Y') as SECONDCONN
             , COUNT(Timedetail) as SECONDOccurances
             , EVENTS 
      FROM  MyDatabase
      WHERE EVENTS = "SECOND" 
      GROUP BY SECONDCONN ;
  &lt;/cfquery&gt; 
  
  
  &lt;cfquery dbtype="query" name="detail2"&gt;
      SELECT  *
      FROM   master2 
      WHERE  SECONDCONN  &gt;= &lt;cfqueryparam value="#form.startdate#" cfsqltype="cf_sql_varchar"&gt; 
      AND    SECONDCONN  &lt;  &lt;cfqueryparam value="#dateAdd('d', 1,form.enddate)#" cfsqltype="cf_sql_varchar"&gt;;
  &lt;/cfquery&gt;  
  
  
  &lt;cfchart format="flash"  chartwidth="1000" chartheight="500" scalefrom="0" scaleto="50000" xAxisTitle="Dates" yaxistitle="Number of Connections"&gt;
       &lt;cfchartseries  query="detail1" type="line" itemColumn="FIRSTCONN" valueColumn="FIRSTOccurances" &gt; 
       &lt;cfchartseries  query="detail2" type="line" itemColumn="SECONDCONN" valueColumn="SECONDOccurances" &gt; 
       &lt;/cfchartseries&gt;
  &lt;/cfchart&gt;[/CODE]
  
  The cfform code and cfscript code I'm using is as follows:
  
  [CODE]&lt;cfform format="flash" preloader ="false"&gt;
  
  
  &lt;cfformgroup type="horizontal"&gt;
  
    &lt;cfinput type="dateField" name="startdate" label="Start Date" width="100" value="#form.startdate#"&gt;
    &lt;cfinput type="dateField" name="enddate" label="End Date" width="100" value="#form.enddate#"&gt;
    &lt;cfinput name="submitApply" type="submit" value = "Apply"&gt;
    &lt;cfinput name="cancel" type="submit" value="Download CSV"&gt;
  
  &lt;/cfformgroup&gt;
  
  
  &lt;cfscript&gt;
      var tl ='';
      var nl = (Chr( 13 ) &amp; Chr( 10 ));
      var fileContent = createObject("java","java.lang.StringBuffer").init();
      var counter =1;
      fileContent.append( 'FIRST');
       fileContent.append(nl);
              for(i=1;i&lt;=detail1.recordCount;i=i+1){
                  tl = detail1.FIRST;
                  fileContent.append(tl);
                  fileContent.append(nl);
              }
  
  
  
  
    fileContent.append( 'SECOND');
       fileContent.append(nl);
              for(i=1;i&lt;=detail2.recordCount;i=i+1){
                  tl = detail2.SECOND;
                  fileContent.append(tl);
                  fileContent.append(nl);
              }           
  
  &lt;/cfscript&gt;
  
  &lt;cfset absoluteFilePathAndName = " C:\ColdFusion8\runtime\servers\coldfusion\SERVER-INF\temp\wwwroot-tmp\"&gt;
  
  &lt;cfset realtiveFilePathAndName = " C:\ColdFusion8\runtime\servers\coldfusion\SERVER-INF\temp\wwwroot-tmp\"&gt;
  
  &lt;cffile action="write" file="#absoluteFilePathAndName#" output="#fileContent.toString()#"/&gt;
  &lt;a href="#realtiveFilePathAndName#&gt;Download&lt;/a&gt; 
  </code></pre>
  
  <p>Desired Output:</p>
  
  <p>I have attached the <img src="https://i.stack.imgur.com/y47iO.jpg" alt="image"> for the output below. Please find it attached.</p>
  
  <p>Basically, if a date range is 21June to 21 July. The output must be as shown in the image. (I have omitted THIRDCONN etc for the sake of simplicity in my code).</p>
  
  <p>I tried to attempt to the above problem,Do I need to write fileContent.append() for each and every column? Please let me know if I'm wrong.</p>
  
  <p>P.S. I'm new to CF and haven't done this before.</p>
  
  <p>Thanks</p>