Parametrizing SQL commands.

I use a TQuery component for SQL commands. I execute a SQL
command using, for exemple, the sequence:
      Query1.Close;
      Query1.SQL.Clear;
      Query1.SQL.Add ('select * from file where Code>= 20');
      Query1.Open;
I want to use Query1.Params property to parametrize the value "20".
How to do that? I need un example.
val84Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
aubsConnect With a Mentor Commented:
Query1.Close;
                      Query1.SQL.Clear;
                      Query1.SQL.Add ('select * from file where Code>= :Code');
                      Query1.ParamByName('Code').AsInteger:= 20;
                      Query1.Open;
0
 
bakry99Commented:
Hi ,,
  You Can do The
      Query1.Close;
      Query1.SQL.Clear;
      Query1.SQL.Add ('select * from file where Code>= '+ Edit1.Text);
      Query1.Open;
0
 
bakry99Commented:
or
st:=   inputBox('','Inout Code You want to search for','');
Query1.SQL.Add ('select * from file where Code>= '+ st);


  Bakry
0
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

 
MotazCommented:
What kind of database did you want to use, is it desktop or Client/Server?

Motaz
0
 
aubsCommented:
Hi Val84,

Something like this perhaps...

Query1.Close;
Query1.SQL.Clear;
Query1.SQL.Add ('select * from file where Code>= :Code');
Query1.ParamByName('Code').AsInteger:= 20;
Query1.Open;

Regards
Aubs

0
 
kretzschmarCommented:
too late, aubs wins :-))
0
 
VolkCommented:
You'll still have to add the parameter though, don't forget to specify a type for the parameter (Integer in your case) when using the Object Inspector. From you code:

Query1.Params.CreateParam (ftInteger, 'Code', ptInput);

You only have to create it once.

Good luck,

JAAP
0
 
VolkCommented:
Volk changed the proposed answer to a comment
0
 
val84Author Commented:
Really Aubs won. I tested it and it's OK.
Thanks all of you. Alex.
0
 
val84Author Commented:
I am late with the acceptance because I had problems with the Net.
Thanks a lot. Alex.
0
All Courses

From novice to tech pro — start learning today.