Solved

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

Posted on 2009-06-30
3
1,454 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 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 29

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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…

730 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