Solved

SQL Output

Posted on 2002-06-23
3
230 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 75 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

Technology Partners: 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

Suggested Solutions

Title # Comments Views Activity
Printing problem 2 124
Wincontrol not (correctly) drawn 15 59
Way to create an iPhone app for my customers 8 89
Automatic field translation delphi 10.2 6 45
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

734 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