with tmpquery do
begin
databasename:=...
sql.text:=...
open;
first;
while not eof do
begin
yourstr:=fields.asString or :=fieldbyname('...').asstring;
next;
end;
end;
query1.close;
query1.sql.clear;
query1.sql.add('select fieldname from table1 where fieldname=fieldvalue');
query1.prepare;
query1.open;
if not query1.empty then varname:=query1.fieldbyname(fieldname).value;