[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


How to use like'%%' with a parameter?

Posted on 2005-04-19
Medium Priority
Last Modified: 2010-03-19
normally I use a like statement like this:
select * from table1 where field like '%something%'

Now I have a @parameter and I need to use a like statement but it seems to only work with strings.  How can I get it to work with parameters? (I am testing it to be used in a stored procedure)

I am trying to write something like this:

declare @parameter varchar(100)
select @parameter = 'test string'

select * from table1 where field like '@parameter'

If it is not possible, is there another way this can be accomplished?
Any help is greatly appreciated.
Question by:new2Java
1 Comment
LVL 28

Accepted Solution

rafrancisco earned 500 total points
ID: 13815421
Try this

WHERE Field LIKE '%' + @parameter + '%'

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question