Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQL Output

Posted on 2002-06-23
3
Medium Priority
?
245 Views
Last Modified: 2010-04-04
Hi,

Could anyone let me know how you would output the results of a SQL query to a .csv file.
Any help would be great,

Thanks
0
Comment
Question by:HotRod40
[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
  • 2
3 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7102936
maybe something like this

sl := tstringlist.create;
try
  query1.open;
  while not query1.eof do
  begin
    for 1 := 0 to query1.fieldcount-1 do
    begin
      s := s + query1.fields[i].asstring;
      if i < query1.fieldcount-1 then
        s := s +','; //or other delimiter
    end;
    sl.add(s);
    query1.next;
  end;
  sl.savetofile('Filename');
finally
  sl.free;
end;

just from head, not tested

meikl ;-)
0
 

Accepted Solution

by:
jamiguel earned 225 total points
ID: 7106566
var
  f:textfile;
begin
  assignfile(f,'c:myf.txt');
  rewrite(f);
  query1.first;
  while not query1.eof do
  begin
    writeln(query1.fieldbyname('Myfield1').asstring+#9+
            inttostr(query1.fieldbyname('Myfield2).asinteger)+#9+formatdatetime('dd/mm/yyyy',query1.fieldbyname('myfield3').asdatetime))
    query1.next;
  end;
  closefile(f);
  messagedlg('Finish',mtinformation,[mnok],0);
end;

NOTE: if u want a character different to #9 (tab) replace #9 by ',' ok?


0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7106581
jamiguel,

its just not polite to answer a question,
when others already has given a solution
in previous comments

for the future, please,
do rather comment than answer a question,
so that the questioner can decide,
which comment helps best

meikl ;-)

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

604 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