Solved

Parametrizing SQL commands.

Posted on 2000-04-04
10
149 Views
Last Modified: 2010-04-04
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.
0
Comment
Question by:val84
  • 2
  • 2
  • 2
  • +3
10 Comments
 
LVL 1

Expert Comment

by:bakry99
ID: 2686411
Hi ,,
  You Can do The
      Query1.Close;
      Query1.SQL.Clear;
      Query1.SQL.Add ('select * from file where Code>= '+ Edit1.Text);
      Query1.Open;
0
 
LVL 1

Expert Comment

by:bakry99
ID: 2686427
or
st:=   inputBox('','Inout Code You want to search for','');
Query1.SQL.Add ('select * from file where Code>= '+ st);


  Bakry
0
 
LVL 7

Expert Comment

by:Motaz
ID: 2686443
What kind of database did you want to use, is it desktop or Client/Server?

Motaz
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 2

Expert Comment

by:aubs
ID: 2686499
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
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2686524
too late, aubs wins :-))
0
 

Expert Comment

by:Volk
ID: 2686703
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
 

Expert Comment

by:Volk
ID: 2686706
Volk changed the proposed answer to a comment
0
 

Author Comment

by:val84
ID: 2686765
Really Aubs won. I tested it and it's OK.
Thanks all of you. Alex.
0
 
LVL 2

Accepted Solution

by:
aubs earned 100 total points
ID: 2686996
Query1.Close;
                      Query1.SQL.Clear;
                      Query1.SQL.Add ('select * from file where Code>= :Code');
                      Query1.ParamByName('Code').AsInteger:= 20;
                      Query1.Open;
0
 

Author Comment

by:val84
ID: 2688771
I am late with the acceptance because I had problems with the Net.
Thanks a lot. Alex.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question