LIKE command

  • Hello,

    I want to run a select command, on the basis of LIKE clause.

    In WHERE condition, I want to include:

    WHERE column1 LIKE '%Column2%'. i.e. I want to include the column_name.

    Is it possible ? Please help

    Thanks in advance!

  • touchmeknot (9/27/2010)


    Hello,

    I want to run a select command, on the basis of LIKE clause.

    In WHERE condition, I want to include:

    WHERE column1 LIKE '%Column2%'. i.e. I want to include the column_name.

    I'm not sure I understand what you are trying to do. Are you trying to find values in column1 that contain what is in column2? Is column2 a N/VARCHAR field?

    If so try this:

    WHERE column1 LIKE '%' + Column2 + '%'

    If that doesn't do it you will need to provide more information. Here is a link that can help you with how to ask the question to get the best answer: http://www.sqlservercentral.com/articles/Best+Practices/61537/

  • How about:

    WHERE Column1 LIKE '%' + Column2 + '%'

    Note that starting off with a '%' will mean that you won't effectively be able to use an index.

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2

  • Thanks UMG Developer :). You provided the solution I was looking for.

    Thanks WayneS.

  • Your welcome, thanks for letting us know that worked for you.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply