Solved

Parametrizing SQL commands.

Posted on 2000-04-04
10
147 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
 
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now