Search by “Match whole word” using MS SQL Query
Search by “Match whole word” using MS SQL Query.
Do you want to search with match whole word in to the filed? For example you are search company name from your company table (tblCompany)
Let me search with
Most SQL Search using the LIKE Keyword to perform keyword search. In these cases this type of search provides undesirable results. For example a uses is searching for an order by company name ‘del’. However a search returns unwanted records.
SELECT *
FROM tblCompany
WHERE (companyname LIKE ‘del%’)
Search Results
?
1)? DELAMERE DESIGN LTD
2)? DELAMERE FINANCIAL SERVICES
3)? DELAMERE SCHOOL
4)? DELICATA COACHBUILDERS & TRAILER MANUFACTURERS? ?
5)? DEL MAR REYNOLDS? ?
This query returns the all record with start from ‘DEL’ from the tblcompany.
thoese records is match with whole word.
1)? DELAMERE DESIGN LTD
2)? DELAMERE FINANCIAL SERVICES
3)? DELAMERE SCHOOL
4)? DELICATA COACHBUILDERS & TRAILER MANUFACTURERS? ?
Whole word for belwo record
5) DEL MAR REYNOLDS?
Search keyword have inside the company name i.e. ‘THE DEL INc.’
in this case SQL Search with the keyword with ‘%keyword%’ for match keyword with inside the company name
SELECT *
FROM tblCompany
WHERE companyname LIKE ‘%del%’
1)? DELAMERE DESIGN LTD
2)? DELAMERE FINANCIAL SERVICES
3)? DELAMERE SCHOOL
4)? DELICATA COACHBUILDERS & TRAILER MANUFACTURERS? ?
5)? DEL MAR REYNOLDS? ?
6)? THE DEL INc
7)? WEDDEL SWIFT LTD
Query returns the all records with match keyword in any where into the company name.
? ? ? ? ?
SELECT *
FROM tblCompany
WHERE companyname LIKE ‘% del %’ or companyname LIKE ‘del %’ or
This ‘% del %’ Search with ‘del’ with before space and after space of the search query string.
This ‘del %’ Search with ‘del’ with after space only
Search Result for the above Query is
1)? THE DEL INC
? ?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?