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
WooCommerce vs Shopify – What’s Good For Your eCommerce Website Development in India?
Feb16

WooCommerce vs Shopify – What’s Good For Your eCommerce Website Development in India?

WooCommerce and Shopify are the two best eCommerce platforms available for you now. Whether you want to develop...
View More
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