Board index » delphi » Writing Query results to a text file

Writing Query results to a text file

Hi again,
        I am trying to get access to a Query's result set so that I can
write the results to a textfile.  Basically, I loading an SQL from a file
that should return a certain number of records.  I want to write this
data to a text file formatted so that Excel can open up this data and
it can be manipulated.  However, I do not know how to access a TQuery's
result set in text format (i.e. I want to get the resulting data I would
normally get if in an SQL environment that allows me to write SQL
commands).  Can anyone help me??

Thanks in advance...

--
Michael

 

Re:Writing Query results to a text file


All you need to do is access each field and build up a string based on the
values, I.e.,

begin
    Query1.Active := true;
    // Assuming three fields, name, surname, telno
    for c := 1 to Query1.RecordCount do
     begin
      TheString := Query1Name.AsString+','+
                            Query1Surname.AsString+','+
                            Query1TelNo.AsString;
      Writeln (TheFile, TheString);
     end;
end;

HTH

Antoine

Quote
Michael Samuel Tam wrote in message <6tk1m3$7e...@nntp.ucs.ubc.ca>...
>Hi again,
> I am trying to get access to a Query's result set so that I can
>write the results to a textfile.  Basically, I loading an SQL from a file
>that should return a certain number of records.  I want to write this
>data to a text file formatted so that Excel can open up this data and
>it can be manipulated.  However, I do not know how to access a TQuery's
>result set in text format (i.e. I want to get the resulting data I would
>normally get if in an SQL environment that allows me to write SQL
>commands).  Can anyone help me??

>Thanks in advance...

>--
>Michael

Other Threads