Board index » delphi » Help: SQL.Add('select *, max(field) as NewField from TableName')

Help: SQL.Add('select *, max(field) as NewField from TableName')

When clicking on the label I get an EDBEnginError with Message Invalid use
of keyword token.

Why doesn't this work?

How should I correct this?

procedure TDisplayNew.ShowMeLabelClick(Sender: TObject);
begin
  With DataModule1.Query1 do begin
    SQL.Clear;
    SQL.Add('select *, max(Field) as NewField from TableName');
    prepare;
    open;
    ShowMeLabel.Caption := FieldByName('NewField').AsString;
  end;
end;

 

Re:Help: SQL.Add('select *, max(field) as NewField from TableName')


Quote
>When clicking on the label I get an EDBEnginError with Message Invalid use
>of keyword token.

That probably means you are using a field or table name in your query that is an
SQL key word.

I assume the code you posted is just generic code.
What is the SQL that actually produces the error?

--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Re:Help: SQL.Add('select *, max(field) as NewField from TableName')


On Fri, 1 Oct 1999 15:33:16 -0500, "Lawrence Leary"

Quote
<le...@haulpak.com> wrote:
>When clicking on the label I get an EDBEnginError with Message Invalid use
>of keyword token.

>Why doesn't this work?
[snip]
>    SQL.Add('select *, max(Field) as NewField from TableName');

Because you can't have '*' together with other fields without
prefixing it with an alias.  You'd have to use:
  select A.*, max(Field) as NewField from TableName A

But also this wouldn't work because you ask to return all records with
'*' and only one value with 'max(Field)'.  This would work (for
example):
  select count(*) as RecCount, max(Field) as NewField from TableName

What are you trying to do?

Jan

Other Threads