Solved

SQL Output

Posted on 2002-06-23
3
214 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

863 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

23 Experts available now in Live!

Get 1:1 Help Now