Concatenate SQLQuery loop result

2

I have a loop that scans a table, I need each row a string type variable to be incremented with the respective records.

Usage FDQuery and FDConnection .

Here's an idea of what I need

var linhas : string;

while not eof do
begin
linhas := linhas + FieldByName('nome').AsString + ', ';
end;

Result I need:

  

Mary, Mark, Ezekiel, ...

    
asked by anonymous 26.09.2017 / 06:14

1 answer

4
var  
  linhas: string;
begin
  FDQuery1.First;
  while not FDQuery1.Eof do
  begin
    linhas := linhas + FDQuery1.FieldByName('nome').AsString + ', ';

    FDQuery1.Next;
  end;
end;

As far as I understand your question, the above code will meet your need by concatenating the Query result in a string. You can also do this in a StringList, follow the code:

var
  linhas: TStringList;
begin
  linhas := TStringList.Create;
  FDQuery1.First;
  while not FDQuery1.Eof do
  begin
    linhas.Add(FDQuery1.FieldByName('nome').AsString);

    FDQuery1.Next;
  end;
end;
    
26.09.2017 / 13:46