Like operator

  • My dataset

    SELECT description

    FROM tab1

    where description = '%@Description%'

    also tried

    SELECT description

    FROM tab1

    where description = '%" + @Description + '%'

    also tried

    SELECT description

    FROM tab1

    where description = '*@Description*'

    I am trying to create a report with a filter on a text field for which I am using like operator . The user will pass a parameter based on the column values(description column) for this like operator.

    But when I run this query it does not result any results.

    Thanks

  • Have you tried this:

    SELECT description

    FROM tab1

    where description = '''%' + @Description + '%'''

    Please note, that is three single quotes at the start and end.

  • Lynn Pettis (5/4/2009)


    Have you tried this:

    SELECT description

    FROM tab1

    where description = '''%' + @Description + '%'''

    Please note, that is three single quotes at the start and end.

    You probably need to change the query from an EQUAL query to an LIKE query (the failure wasn't caused by the single quotes):

    SELECT description

    FROM tab1

    where description LIKE '%' + @Description + '%'



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • lmu92 (5/4/2009)


    Lynn Pettis (5/4/2009)


    Have you tried this:

    SELECT description

    FROM tab1

    where description = '''%' + @Description + '%'''

    Please note, that is three single quotes at the start and end.

    You probably need to change the query from an EQUAL query to an LIKE query (the failure wasn't caused by the single quotes):

    SELECT description

    FROM tab1

    where description LIKE '%' + @Description + '%'

    Good catch, didn't see the forest for the trees.

Viewing 4 posts - 1 through 3 (of 3 total)

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