Solved

Parametrizing SQL commands.

Posted on 2000-04-04
10
151 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

735 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