[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2009-06-30
3
Medium Priority
?
1,464 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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
The purpose of this video is to demonstrate how to automatically show related posts at the bottom of a blog post in WordPress. This will be demonstrated using a Windows 8 PC. Plugin “Yet Another Related Posts Plugin” will be used. Go to your…
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…
Suggested Courses

649 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