Link to home
Start Free TrialLog in
Avatar of selas
selas

asked on

how to get information?

on create i get error: field '`1`' not found

<-- code  -->
procedure TForm3.FormCreate(Sender: TObject);
begin
PComputerName:= StrAlloc(100); Size:= 100;
if GetComputerName(PComputerName, Size) then
pc := PcomputerName;
Form1.AdoQuery2.SQL.Clear;
Form1.AdoQuery2.SQL.Add('select `1`, `2.5`, `5`, `10`, `20`, `50`, `100`, `500`, `1000`, `time` from chips');
Form1.AdoQuery2.ExecSQL;
Label1.Caption := Form1.Adoquery2.FieldByName('`1`').Value;
Label2.Caption := Form1.Adoquery2.FieldByName('`2.5`').Value;
Label3.Caption := Form1.Adoquery2.FieldByName('`5`').Value;
Label4.Caption := Form1.Adoquery2.FieldByName('`10`').Value;
Label5.Caption := Form1.Adoquery2.FieldByName('`20`').Value;
end;

HOW TO FIX IT?
Avatar of Amir Azhdari
Amir Azhdari
Flag of United States of America image

what's usage of this character!!? -- > `
I think it's invalid character for field name
Avatar of Lukasz Lach
Lukasz Lach

When writing:
  select `1`, `2.5`, `5`, `10`, `20`, `50`, `100`, `500`, `1000`, `time` from chips
SQL interprets it as a field names 1, 2.5, 5, 10... These are not names of fields (as i think you didn't meant it and that kind of names are invalid anyway). If you wanted to select numbers, write:
  select 1, 2.5, 5, 10, 20, 50, 100, 500, 1000, `time` from chips
The only field name here is `time`. remember, that when you put something between `...` in SQL it's *always* interpreted as a *name* of field, table etc.
i'm really mixed about :( , but when we write :
select `1`, `2.5`, `5`, `10`, `20`, `50`, `100`, `500`, `1000`, `time` from chips

SQL interprets these as parameters , not as field names.
>The only field name here is `time`. remember, that when you put something between `...` in SQL it's *always* interpreted as a *name* of field, table etc.

then what's differ when we write :
select time from table
aren't you in mistake about ` and ' characters ?
no, i'm not. mind the example:

mysql> select 1;
+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0.00 sec)

mysql> select `1`;
ERROR 1054: Unknown column '1' in 'field list'
mysql>
I'm agree with you about this, :)

but ERROR 1054 is because of sql interprets `1`, `2.5`, ... as parameters not as field names
Well, that's "Unknown column '1' in 'field list'", so there is no column named '1' to be taken...
Hi

Looking a this you have created a field with the name `1`  not  '1' as some people have interpreted. These are not pseudo fields as some people have interpreted (as they would have had to be defined more clearly (1 as Integer etc..., 1 as DateTime etc...)

If you had used the ' and not the ` it would not compile anyway.....

The use of ` as a character in a fieldname is almost certainly invalid (and anyway is bad practice) all field names should contain only alpha numeric characters and underscores (spaces are allowed but frowned on).

It is also bad practice to use spaces and equally bad practice to use the '.' period (I am surprised that any database would allow this).  This has surely only been allowed in the context of the erroneous ` character.

Amir Azhdari is certainly correct in this.

Change the fieldnames to something sensible without the erroneous ` characters (these are not quotation marks - what are they - I see them every day on my keyboard and have not thought of it!) and without the Erroneous '.' periods.

Change them to (example).

1,2.5 (if you must use numbers)

Or One, TwoPointFive etc

If you must use numbers access them like this

Select [1],[2.5] etc

I would never do this myself unless absolutely forced to do so.


Voodooman
Avatar of selas

ASKER

1, 2.5, 5, 10, 20, 50, 100, 500, 1000, time - column names

then i exec sql: select `1`, `2.5` from chips

i need to get value of column 1 and 2.5

Hi

You cant use the character ` in your SQL

Try this

select [1], [2.5],[5],[10],[20],[50],[100],[500],[1000] from chips


Voodooman
Avatar of selas

ASKER

if i use:

Form1.AdoQuery2.SQL.Clear;
Form1.AdoQuery2.SQL.Add('Select [1],[2.5], [5], [10], [20], max(time) from chips group by ivede');
Form1.AdoQuery2.ExecSQL;

i get error in syntax...

Hi

Well I see that your problem over the field not found is cured using the [ ] - so I have answered your question.

You will get a syntax error with the new query.

max(Time) would have to be a field called time which is probably a reserved word and you could't use it anyway - perhaps max([Time]) might work.

However you can't group by a field that is not included in an aggregate of some kind - so you will have an error in the syntax.

As your original problem is solved, I suggest you accept the answer and ask another question related to your new query.

Voodooman
ASKER CERTIFIED SOLUTION
Avatar of Ivanov_G
Ivanov_G
Flag of Bulgaria image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

Form1.AdoQuery2.SQL.Clear;
Form1.AdoQuery2.SQL.Add('Select ivede,[1],[2.5], [5], [10], [20], max([time]) from chips group by ivede');
Form1.AdoQuery2.ExecSQL;

This should work if you have a column called time and a column called ivede

Voodooman

Well it seems that giving the correct answer dosnt seem to matter anymore...... maybe thats why very few people come here compared to when I first started in 1989.

I don't what to be petty but I think selas is wrong in his acceptance of the answer of Ivanov_G.

I am disgusted is all I can say....

Voodooman