Solved

How do I create a  csv file with coldfusion 8 and a SQL Query?

Posted on 2009-06-30
3
1,443 Views
Last Modified: 2013-12-20
How do I  a create csv file from a SQL query and using coldfusion?

Selec t *  from table
and set as csv
???
<cfset file as "csvfile">
then upload "csvfile".
0
Comment
Question by:LeadCo
3 Comments
 
LVL 8

Accepted Solution

by:
MartinCMS earned 250 total points
ID: 24753710
Try something like this...

<CFQUERY name="Get_CSV" datasource="yourDataSource">
SELECT       F1,F2
FROM       yourTable
</CFQUERY>

<CFSET TXTOUTPUT = "">
<CFSET OUTFILE = "C:\testFile.csv">

<CFSET TXTCOLUMNS = '"F1","F2"'>
<CFIF #FILEEXISTS(OUTFILE)# IS "No">
      <CFFILE ACTION="WRITE" FILE="#OUTFILE#" OUTPUT="#TXTCOLUMNS#">
</CFIF>
<CFLOOP QUERY="Get_CSV">
      <CFSET TXTOUTPUT = '"#F1#","#F2#">
      <CFFILE ACTION="APPEND" FILE="#OUTFILE#" OUTPUT="#TXTOUTPUT#">      
</CFLOOP>
<CFSET filename = "testFile.csv">
<CFHEADER  NAME="content-disposition" VALUE="attachment; filename=#filename#">
<CFCONTENT  TYPE="APPLICATION/MSEXCEL" FILE="#OUTFILE#" DELETEFILE="TRUE" RESET="TRUE">
0
 
LVL 28

Assisted Solution

by:Pravin Asar
Pravin Asar earned 250 total points
ID: 24763185
0
 

Author Closing Comment

by:LeadCo
ID: 31598361
Thanks!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now