How to amatch whole word in SQL

How to amatch whole word in SQL

Alex
March 28, 2010

Problem

How to match whole word in SQL.

We very frequently face the requirement to match an entire word, while developing the website/application.

Solution

This problem can be very easily handled by Microsoft SQL query.
For example when you search for “ram”, if you use “%ram%” it will also match “programme”.

To resolve this, we can use regular expression like syntax in SQL.
The below query will only return the title having “ram” and not “programme”.

select title from article where ‘ ‘+title like ‘%[ ]ram[ ]%’

Additionally we also can provide extra characters to match after word like
select title from article where ‘ ‘+title like ‘%[ -_]ram[ .-_]%’

Enjoy working with SQL.More

Recent News Post
iPhone 14 and iPhone 14 Pro – Let’s Learn More About its Features, Specs, and Prices
Oct11

iPhone 14 and iPhone 14 Pro – Let’s Learn More About its Features, Specs, and Prices

Finally, the wait is over, and the legendary iPhone 14 by Apple Inc. is here to spellbind all...
View More
Hire Qualified ASP.Net Developers to Explore New Business Horizons in 2022
Sep20

Hire Qualified ASP.Net Developers to Explore New Business Horizons in 2022

In 2022, it is fruitful in many ways to hire asp.net developers – ASP.NET development is affordable, secure,...
View More