Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 546
  • Last Modified:

Delphi parametrised SQL query

Delphi parameter sql queries I think I have a need that would require there use but am not sure how to use it in the ide or programatically

I have the following sql statement

select class_id from class, subjects where class.subject_id = subjects.sub_id AND class.teach_id = '17' AND subjects.Aca_Lvl = 7

I have a variable which I want to test against, that contains the value for
class.teach_id and a second variable that contains
subjects.aca_lvl

Would I use a parameterised query? If so how would I do this

Thanks

Jake
0
elschott
Asked:
elschott
1 Solution
 
spk2000arCommented:
Yes, use a sql with parameters like this.

At SQL.Strings:

select class_id from class, subjects where class.subject_id = subjects.sub_id AND class.teach_id = :class.teach_id AND subjects.Aca_Lvl = :subjects.Aca_Lvl

Then when you save this code... go to Params property, and set the type of both parameters.

When you call the query do something like this:

with Tquery1 do
  begin
    close;
    parambyname('class.teach_id').asstring := QuotedStr(IntToStr(17)); //use 17 as in your sample,
    parambyname('subjects.Aca_Lvl').asinteger := 7; //use any value you like!
    prepare;
    open;
  end;

Hope this help!!
0

Featured Post

Technology Partners: 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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now