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
elschottAsked:
Who is Participating?
 
Martin BarredaConnect With a Mentor Lic. in Computer ScienceCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.