Board index » delphi » Please help with Delphi SQL syntax problem

Please help with Delphi SQL syntax problem

I have a form with 2 DBLookupDialogs.  Each of those will
select a value that I need to use in a Query clause to
select data from another table for display in  a third

How on earth do I get the syntax to work in the code to
use both DBLookupCombos text values?

I have tried many variations but obvious don't understand it.

with wwQuery1 do
    SQL.Add('select MyFieldName from "table1.db" where ????

I need this syntax to use the text from each of the lookups
as my where clause, with an AND i think.

Please help!


Re:Please help with Delphi SQL syntax problem

You could use something like this

constMyQuery = 'select MyFieldName from table1 where
lookupField1=''%s'' and lookupField2=''%s''';

NB SQL.Clear calls close automatically.

NB Format will reaplce the first %s with the first of the parameters
in the square brackets and the second %s with the second argument.

The above assumes that both the lookup values are strings, if either
or both aren't then get rid of the two single quotes on either side of
the relevant %s.

Please keep spamming my email account. I don't mind because I don't read it.
"Cure Spammers for ever, Shoot the b*st**ds" Tony

Re:Please help with Delphi SQL syntax problem

Perhaps you can use a TQuery comp. usin de .text value of your
DBLookupDialogs as TQuery parameters.

The SQL property of TQuery1 would be something like this

'SELECT myFieldName
 FROM table1
 WHERE (condition1= :c1) AND (condition2=:c2)'

next, in your code you can write somethig like this

  TQuery1.Parameters[0].value:= DBLookupDialog1.text;
  TQuery1.Parameters[1].value:= DBLookupDialog2.text;
  TQuery1.Open; // (or Execute, it depensd on the result set)

in the appropiate event.

Don`t forget to define the parameter's type in the TQuery1 properties.

Good luck.

Other Threads