9 Replies - 18153 Views - Last Post: 16 November 2011 - 02:54 PM Rate Topic: -----

#1 raka-exotica  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 07-November 11

Using LIKE in SQL Statement

Posted 13 November 2011 - 10:12 AM

I am developing a library application using VB 6.0 As front end and Microsoft Access as Back end.

I want to search by keywords and i have used the following SQL statement in VB

"SELECT * From Daily_Book WHERE Bookname Like' "& Text1.Text & " ' %"

Daily_Book is my table name and Bookname is the column name.
I want to enter the keyword in Text1.Text (say C++) And search all books with C++ in the table Daily_Book

I executed the above code ..it gives me syntax errors....

Is This A Good Question/Topic? 0
  • +

Replies To: Using LIKE in SQL Statement

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 5186
  • View blog
  • Posts: 13,916
  • Joined: 18-April 07

Re: Using LIKE in SQL Statement

Posted 13 November 2011 - 10:58 AM

You need to put in some spaces. Right now you have the words "like", the single quotes, the text from Text1 and your percentage symbol all smashed together. Plus the percentage goes on the INSIDE of the single quotes.

"Select * from Daily_Book where Bookname Like '" & Text1.Text & "%'"



Notice above we have a space in between the Like and single quote, the percentage sign is also inside of the right single quote. Try this. It should work.

:)
Was This Post Helpful? 0
  • +
  • -

#3 raka-exotica  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 07-November 11

Re: Using LIKE in SQL Statement

Posted 13 November 2011 - 10:15 PM

View PostMartyr2, on 13 November 2011 - 10:58 AM, said:

You need to put in some spaces. Right now you have the words "like", the single quotes, the text from Text1 and your percentage symbol all smashed together. Plus the percentage goes on the INSIDE of the single quotes.

"Select * from Daily_Book where Bookname Like '" & Text1.Text & "%'"



Notice above we have a space in between the Like and single quote, the percentage sign is also inside of the right single quote. Try this. It should work.

:)


Thanks, it worked. But I want to search some what different. Suppose in the library there are book as follows.
1) C++ learn in 24 Hours
2) Learn C++ in 24 Hours
3) New techniques in C++
These are the books available in the library. I will type only single word say C++. My requirement is that, after query is processed, it should display all three above books, because C++ is common word or string in all of them.
So please help me.
Was This Post Helpful? 0
  • +
  • -

#4 raka-exotica  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 07-November 11

Re: Using LIKE in SQL Statement

Posted 14 November 2011 - 12:17 AM

I want to search some what different. Suppose in the library there are book as follows.
1) C++ learn in 24 Hours
2) Learn C++ in 24 Hours
3) New techniques in C++
These are the books available in the library. I will type only single word say C++. My requirement is that, after query is processed, it should display all three above books, because C++ is common word or string in all of them.
So please help me.
Was This Post Helpful? 0
  • +
  • -

#5 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13959
  • View blog
  • Posts: 55,712
  • Joined: 12-June 08

Re: Using LIKE in SQL Statement

Posted 14 November 2011 - 05:44 AM

Most strings have a 'contains' function (usually an instr) or you could write that yourself using a for loop for each string in an array and then a second for loop comparing the search text's characters with each string.
Was This Post Helpful? 0
  • +
  • -

#6 guyfromri  Icon User is offline

  • D.I.C Addict

Reputation: 46
  • View blog
  • Posts: 836
  • Joined: 16-September 09

Re: Using LIKE in SQL Statement

Posted 14 November 2011 - 07:33 AM

View Postmodi123_1, on 14 November 2011 - 07:44 AM, said:

Most strings have a 'contains' function (usually an instr) or you could write that yourself using a for loop for each string in an array and then a second for loop comparing the search text's characters with each string.


I would definitely go instr...just to add to this a bit though...I've used this function A LOT when writing my programs and have found that to get the most effective use out of it, you should convert the case of alphabetic characters. It compares exact case...

For instance
str="c++ 24 Hours"

if instr(1, UCase(str), "C++") then msgbox "Found me!!"



Just cause I'm chatty today :)

This post has been edited by guyfromri: 14 November 2011 - 07:34 AM

Was This Post Helpful? 0
  • +
  • -

#7 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 180
  • View blog
  • Posts: 1,607
  • Joined: 17-April 07

Re: Using LIKE in SQL Statement

Posted 15 November 2011 - 01:43 AM

put the % before and after
"Select * from Daily_Book where Bookname Like '%" & Text1.Text & "%'"


Was This Post Helpful? 1
  • +
  • -

#8 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 180
  • View blog
  • Posts: 1,607
  • Joined: 17-April 07

Re: Using LIKE in SQL Statement

Posted 15 November 2011 - 01:45 AM

you will get the answer in your previous questions? that's why we told you to don't create duplicate topics
Was This Post Helpful? 0
  • +
  • -

#9 Raaj71  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 69
  • Joined: 21-October 11

Re: Using LIKE in SQL Statement

Posted 15 November 2011 - 02:37 AM

"SELECT * FROM Address WHERE First_Name LIKE ('" & txtSearch.Text & "%')"




My recent encounter with SQL. :bigsmile:

But Sorry ! This is what you already were doing and i did not read your question carefully. Seems Thava's reply is right in this situation.
Was This Post Helpful? 0
  • +
  • -

#10 BobRodes  Icon User is offline

  • Lovable Curmudgeon
  • member icon

Reputation: 600
  • View blog
  • Posts: 3,069
  • Joined: 19-May 09

Re: Using LIKE in SQL Statement

Posted 16 November 2011 - 02:54 PM

View Postraka-exotica, on 14 November 2011 - 08:17 AM, said:

I want to search some what different. Suppose in the library there are book as follows.
1) C++ learn in 24 Hours
2) Learn C++ in 24 Hours
3) New techniques in C++
These are the books available in the library. I will type only single word say C++. My requirement is that, after query is processed, it should display all three above books, because C++ is common word or string in all of them.
So please help me.

Duplicate topics merged. Please refrain from posting the same question twice. You'll notice that when you asked the question again, you didn't mention SQL, and you got a bunch of answers that didn't help you.

Your WHERE clause should say WHERE BookName LIKE '%C++%' if you want to do exactly what you say above.

This post has been edited by BobRodes: 16 November 2011 - 02:58 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1