Link to home
Start Free TrialLog in
Avatar of aspsue
aspsue

asked on

How can I write a CF query to a Text file?

Instead of writing my query to a table, I want to write it to a text file.
Can someone help me with the code/syntax?

Sue
Avatar of James Rodgers
James Rodgers
Flag of Canada image

you could output the query to a variable in the format that you want to have it stored

<cfset var="">

<cfouptput query="yourquery">
cfset var= #var#+ #field1#,#field2#,#field3#\n \\ not sure about the "\n" might need to be ascii char for newline

<\cfoutput>

and then use

<cffile action="write" file="path/to/file.txt" output="#var#" addnewline="no">

or you might be able to output the query within the cffile tag

output="<cfouptput query="yourquery">cfset var= #var#+ #field1#,#field2#,#field3#\n \\ not sure about the "\n" might need to be ascii char for newline <\cfoutput>"  \\all in one line
output="<cfouptput query="yourquery">cfset var= #var#+ #field1#,#field2#,#field3#\n \\ not sure about the "\n" might need to be ascii char for newline <\cfoutput>"  \\all in one line

should be

output="<cfouptput query="yourquery">#field1#,#field2#,#field3#\n <\cfoutput>"  \\all in one line
ASKER CERTIFIED SOLUTION
Avatar of ericm123
ericm123

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial