Recent

Author Topic: SQL with parameter and wildcard  (Read 2171 times)

tinytim33

  • Jr. Member
  • **
  • Posts: 61
  • Looking for Slick Mode
SQL with parameter and wildcard
« on: February 19, 2015, 11:07:31 pm »
HI, I know this is a lazarus forum, but I'm using Delphi and i hope the same solution applies here.

I simply want to run an SQL statement that takes a letter(s) entered into a textbox and returns results where names of books have the same first letter(s). E.g. if the user enters H into the textbox edtBookTitle, then books such as 'Happy Days','Heaven', 'Hoping for Tomorrow' would be returned. Here is what I have used, but i get no results. The textbox into which the letter is entered is edtBookTitle.text. Hope this makes sense.

Code: [Select]
qbook.SQL.Text:='SELECT BookID,BookTitle FROM Book WHERE BookTitle LIKE CONCAT("edtBookTitle.text","%")';
I get no results when i run the query.

tinytim33

  • Jr. Member
  • **
  • Posts: 61
  • Looking for Slick Mode
Re: SQL with parameter and wildcard
« Reply #1 on: February 19, 2015, 11:18:38 pm »
Just figured it out. I need to learn my apostrophes better!

Code: [Select]
qbook.SQL.Text:='SELECT BookID,BookTitle FROM Book WHERE BookTitle LIKE CONCAT("'+edtBookTitle.text+'%")';
 qbook.open;

 

TinyPortal © 2005-2018