Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Search with string including space.

Author  Topic 

hspatil31
Posting Yak Master

182 Posts

Posted - 2013-03-04 : 08:53:43
Dear All,

I am trying following query for search the record by string name.
When I searching with single word like 'build' I am getting records.
But when I am searching with like 'build computer', I am not getting any records.
Can anyone please help me how to search including space in string ?

Query:

SELECT * FROM PRODUCT WHERE NAME LIKE '%build%'

Thanks,
Harish Patil

Thanks and Regard's
Harish Patil

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-03-04 : 08:56:32
May be one of the following? Each is implementing a different logic.
SELECT * FROM PRODUCT WHERE NAME LIKE '%build computer%'
SELECT * FROM PRODUCT WHERE NAME LIKE '%build%computer%'
SELECT * FROM product WHERE NAME LIKE '%build%' AND NAME LIKE '%computer%'
SELECT * FROM product WHERE NAME LIKE '%build%' OR NAME LIKE '%computer%'
Go to Top of Page

hspatil31
Posting Yak Master

182 Posts

Posted - 2013-03-04 : 09:32:37
Hello John,

Actually I want to search whose name contains the build also and computer also.
Means it should consider the separate word.
Can you please tell me how to do this ?



Thanks and Regard's
Harish Patil
Go to Top of Page

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-03-04 : 09:58:23
Actually I am the third one in the gallery here, not the fourth. But, that aside, the third query I posted would work for what you described:
SELECT * FROM product WHERE NAME LIKE '%build%' AND NAME LIKE '%computer%'
Go to Top of Page
   

- Advertisement -