Board index » delphi » Simple (?) Query problem

Simple (?) Query problem

Hi, i  have a problem.

I'm trying to select the right cars from table1 using the car types from
table2.

Table1 - Cars                Field      Type
                                       Code        A         Index
(Alphanum)
                                       Cartype    S
(ShortInt)
                                       Engine     A
(Alphanum)

Table2 - Type of cars  Field      Type
                                       Type       S           Index
(ShortInt)
                                        Desc     A
(Alphanum)

I select the value of Table2.Type with a DBLookupComboBox.
It returns the right value.

But when i execute the following Query, Delphi gives an error:
"Invalid field name 'Table2.Type' "

Query_type.Close;
Query_type.SQL.Clear;
Query_type.SQL.Add ('SELECT *');
Query_type.SQL.Add ('FROM Table1');
Query_type.SQL.Add ('WHERE Cartype = Table2.Type');
Query_type.Prepare;
Query_type.Open;

Does anyone know what i am doing wrong ?

 

Re:Simple (?) Query problem


Henk,

Table2.type is in a quoted literal so it's not evaluated.  You could either
do

Query_type.SQL.Add ('WHERE Cartype = ' + Table2.Type);
or
Use a parameter for Table2.Type

Hope that helps.

Greg

Using a parameter for Table2.type should fix it.

Quote
Henk wrote in message <7jrlqq$9l...@zonnetje.NL.net>...
>Hi, i  have a problem.

>I'm trying to select the right cars from table1 using the car types from
>table2.

>Table1 - Cars                Field      Type
>                                       Code        A         Index
>(Alphanum)
>                                       Cartype    S
>(ShortInt)
>                                       Engine     A
>(Alphanum)

>Table2 - Type of cars  Field      Type
>                                       Type       S           Index
>(ShortInt)
>                                        Desc     A
>(Alphanum)

>I select the value of Table2.Type with a DBLookupComboBox.
>It returns the right value.

>But when i execute the following Query, Delphi gives an error:
>"Invalid field name 'Table2.Type' "

>Query_type.Close;
>Query_type.SQL.Clear;
>Query_type.SQL.Add ('SELECT *');
>Query_type.SQL.Add ('FROM Table1');
>Query_type.SQL.Add ('WHERE Cartype = Table2.Type');
>Query_type.Prepare;
>Query_type.Open;

>Does anyone know what i am doing wrong ?

Other Threads