I am trying to take the result of a query and put it into a CSV file to then email to the user. All of the data in the CSV file is correct, but I'm also getting the HTML elements for some reason. Here is my code:
<cffunction name="ledgerTest" access="remote" >
<cfquery name="ledgerCheck" datasource="RBDMS_UPDATE">
SELECT * FROM dbo.OOGNS_Schedules
</cfquery>
<cfoutput>
<cfsavecontent variable="myCSV">
<div>
<table border="1">
<thead align="center">
<th>Job Key</th>
<th>INSPECTOR</th>
<th>PERMIT USER</th>
<th>START DATE</th>
<th>END DATE</th>
</thead>
<cfloop query="ledgerCheck">
<tr align="left">
<td>#JobKey#</td>
<td>#Inspector#</td>
<td>#permitUser#</td>
<td>#StartDate#</td>
<td>#EndDate#</td>
</tr>
</cfloop>
</table>
</div>
</cfsavecontent>
</cfoutput>
<cffile action="write" file="temp/ok.csv" output="#myCSV#" />
</cffunction>
And here is the resulting CSV file (I blacked out peoples email address's):
I think that the issue may have to do with the tag because without it I don't get the data from the query. Without the tag the CSV file contains only my code exactly. Yet, regardless of where I move the tag the result is the same.