?
Solved

SQL Output

Posted on 2002-06-23
3
Medium Priority
?
238 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

752 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