Assignment error when assigning a value to a parameterized query parameter

I use Delphi XE2 with the AnyDac and Advantage Database 10 components. In my code, I use parameterized queries as follows:

q.SQL.Text := 'SELECT * FROM Table1 ' +
  'LEFT JOIN Table2 ON (Table1.ID = Table1 .ID_Table2) ' +
  'WHERE ' +
  ':0 BETWEEN Table1.StartAm AND Table1.EndeAm ' +
  'AND Table2 = :1';
q.Params[0].Value := AStartDateTime;
q.Params[1].Value := AIDRessourcenGruppe;
q.Open;

this ends up in an exception:

Exception der Klasse EADSNativeException mit der Meldung '[AnyDAC] [Phys] [ADS] Error 7200: AQE error: state = 22018;
NativeError = 2112; [iAnywhere Solutions] [Advantage SQL Engine] Assignment error 'aufgetreten.

Of course, AStartDateTime is a valid TDateTime delphi value, AIDRessourcenGruppe is an integer value.

interestingly, these two options work:

q.SQL.Text := 'SELECT * FROM Table1 ' +
  'LEFT JOIN Table2 ON (Table1.ID = Table1 .ID_Table2) ' +
  'WHERE ' +
  ':0 BETWEEN Table1.StartAm AND Table1.EndeAm ' +
  'AND Table2 = :1';
q.Params[0].AsDateTime:= AStartDateTime;
q.Params[1].AsInteger:= AIDRessourcenGruppe;
q.Open;

-

q.SQL.Text := 'SELECT * FROM Table1 ' +
  'LEFT JOIN Table2 ON (Table1.ID = Table1 .ID_Table2) ' +
  'WHERE ' +
  ':SomeDate BETWEEN Table1.StartAm AND Table1.EndeAm ' +
  'AND Table2 = :ID_PT_Ressourcengruppe';
q.ParamByName('SomeDate').Value := AStartDateTime;
q.ParamByName('ID_PT_Ressourcengruppe').Value := AIDRessourcenGruppe;
q.Open;

Did I miss something? Thanks for any help!

+5
source
1

- :

, Value , . , , Variant, . - AnyDAC!

AsType:

, Value , :-)
AsType typecast , :

  • , , , , Value Variant

  • , , . string AsDateTime ,

, , , .

+3

All Articles