Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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 article provides a case study on how our local youth baseball league deployed a new website, including the platform selection, implementation and benefits to the league.
The purpose of this video is to demonstrate how to insert an Iframe into WordPress. 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 : Open Page or Post…
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. …

760 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

18 Experts available now in Live!

Get 1:1 Help Now