Topic: syntax help

How can I put SQL result in variable and then read each value from variable.
Example
myvariable  := SQLExecute('SELECT Contracts.id, Clients.company,Contracts.contractno,Products.prodname FROM Contracts INNER JOIN clients ON clients.id = contracts.id_clients INNER JOIN products ON products.id = contracts.id_products WHERE Contracts.id = 2');
showmessage(first value in myvariable);
showmessage(second value in myvariable);
showmessage(third value in myvariable);

Thanks for help

Re: syntax help

Please, download latest beta version 1.48, where I added new function SQLQuery
https://www.dropbox.com/s/6rz92s72djtmv … 8.zip?dl=0


Example:

procedure Form1_Button1_OnClick (Sender: string; var Cancel: boolean);  
var
    Results: TDataSet;
begin
    SQLQuery('SELECT FirstName, LastName FROM person', Results);
    while not Results.Eof do
    begin
        Form1.Memo1.Lines.Add( Results.FieldByName('FirstName').AsString+' '+ Results.FieldByName('LastName').AsString);
        Results.Next;
    end;
    Results.Free;
end;
Dmitry.

Re: syntax help

Thanks Dimitri

Problem is I am working on testing in version 1.42 beta. Is there a work around so I can do it? I just need to put database values in label captions?

Re: syntax help

In your case, you need make three SQLExecute

myvariable  := SQLExecute('SELECT Clients.company FROM Contracts INNER JOIN clients ON clients.id = contracts.id_clients INNER JOIN products ON products.id = contracts.id_products WHERE Contracts.id = 2');
showmessage(myvariable);

myvariable  := SQLExecute('SELECT Clients.contractno FROM Contracts INNER JOIN clients ON clients.id = contracts.id_clients INNER JOIN products ON products.id = contracts.id_products WHERE Contracts.id = 2');
showmessage(myvariable);

myvariable  := SQLExecute('SELECT Products.prodname FROM Contracts INNER JOIN clients ON clients.id = contracts.id_clients INNER JOIN products ON products.id = contracts.id_products WHERE Contracts.id = 2');
showmessage(myvariable);
Dmitry.

Re: syntax help

Thanks Dimitri, wish one could retrieve the whole record once without 3 SQL calls to database.

Re: syntax help

ndinotamba wrote:

Thanks Dimitri, wish one could retrieve the whole record once without 3 SQL calls to database.

For it you should use SQLQuery in the latest beta version.

Dmitry.