Solved

SQL Output

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

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…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 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

22 Experts available now in Live!

Get 1:1 Help Now