How to change Search query that contain particular word n Sql

Hi Experts ,

We need to search in database with the record contains particular Data in it e.g. name column could search for all words that contains  'jon' in it. Is this correct query

my code
SELECT Name FROM Person WHERE Name LIKE '%Jon%'

Open in new window

karthik80cAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Lokesh B RDeveloperCommented:
Hi,

yes it is correct.

It will look for the word where it contains "Jon" in the Name column.
karthik80cAuthor Commented:
Hi Lokesh ,

What if i need to go for exact match
Lokesh B RDeveloperCommented:
Hi,

Exact Match

SELECT Name FROM Person WHERE Name = 'Jon';

Open in new window

Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

Deepak ChauhanSQL Server DBACommented:
In this case you can run

SELECT Name FROM Person WHERE Name LIKE 'jon' 

Open in new window

MohitPanditCommented:
It would work, but you need to change name at run time then below code will work

create table person (pid int identity primary key, name nvarchar(50))

insert into person (name)
values ('jon kumar')

insert into person (name)
values ('jon1 kumar')

insert into person (name)
values ('Ramjon kumar')

insert into person (name)
values ('Ram kumar')

DECLARE
	@Var nvarchar(100) = 'Jon'
SELECT
	*
FROM Person
WHERE name like '%' + @Var +'%'

Open in new window


Your note, database; in case you need to search in then LIKE would be good but for database; please use full text search.

Best Regards

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
karthik80cAuthor Commented:
Thank You Experts For Your Great Effort
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.