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

Posted on 2005-04-19
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

    Try this

    SELECT * FROM Table1
    WHERE Field LIKE '%' + @parameter + '%'

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    The steps for moving the system databases to a new location are documented in the following technical article: However sometimes after the moving process is finished, though SQL i…
    Performance is the key factor for any successful data integration project, knowing the type of transformation that you’re using is the first step on optimizing the SSIS flow performance, by utilizing the correct transformation or the design alternat…
    Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
    Viewers will learn how the fundamental information of how to create a table.

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now