?
Solved

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

Posted on 2009-06-30
3
Medium Priority
?
1,462 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 8

Accepted Solution

by:
MartinCMS earned 1000 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 29

Assisted Solution

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

Author Closing Comment

by:LeadCo
ID: 31598361
Thanks!
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
The purpose of this video is to demonstrate how to make a WordPress Site faster and smaller in size by cleaning up the database. This will be demonstrated using a Windows 8 PC. Plugin WP Optimize will be used. Go to your WordPress login page. T…
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…
Suggested Courses

762 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