<!--- GET RESULTSET --->
<cfquery name="getUser" datasource="#ds#">
SELECT User_ID, FirstName, LastName, City, State, Zip, Email
FROM myTable mT INNER JOIN Users U ON mT.User_ID = U.User_ID
</cfquery>
<!--- sets the delimeter to doublequotes ["] --->
<cfset delimiter = chr(34)>
<!--- sets the text delimqual to: doublequotes comma doublequote [ "," ]. This is the closing quote, comma, opening quote.--->
<cfset delimqual = chr(34)&chr(44)&chr(34)>
<!--- sets the FileName var to a specific file name. This is the file that gets emailed to the client, or FTP'd --->
<cfset FileName="GUJUm0deLExample_#DateFormat(now(),'mmddyyyy')#.txt">
<!--- sets the FullPathName to retrieve the file from the server from our side --->
<cfset FullPathName = "#getdirectoryfrompath(gettemplatepath())#files\#FileName#">
<!--- write to the file with certian outputs. Since this resides before the loop, this will be the 'header' of the file --->
<cffile action="write" file="#FullPathName#" output="#delimiter#First Name#delimqual#Last Name#delimqual#City#delimqual#State#delimqual#Zip#delimqual#Email#delimiter#" addnewline="Yes">
<!--- outputs the query from above and groups it by the user id --->
<cfoutput query="getUser" group="User_ID">
<cffile action="append" file="#FullPathName#" output="#delimiter##FirstName##delimqual##LastName##delimqual##City##delimqual##State##delimqual##Zip##delimqual##Email##delimiter#" addnewline="Yes">
</cfoutput>