LIKE%

  • Hey guys how can i use the "like" in a Case statement?

     

    thx much

     

  • Can you provide an example of what you are trying to do and include sample data and results?

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • just want sripts man

    Select

    Case when find_This = Like '%Pleasehelpme'   else 'u_Can't' end as [Can You]

    etc

     

  • I'm still not exactly sure what you're after but here you go:

     

    DECLARE @table TABLE (value varchar(100))

    INSERT INTO  @table

    SELECT 'Please help me because I cant help myself' UNION ALL

    SELECT 'u cant help me because my example stinks'

    SELECT

        CASE WHEN value LIKE 'Please help me%' THEN value END AS 'Yes, I can',

        CASE WHEN value LIKE 'u cant%' THEN value END AS 'No, I cannot'

    FROM @table

     

    beware of using LIKE '%value' as it will cause table scans!

     

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • Yes, your syntax is incorrect in your example. The question, if not answered by the above, is "What is your goal"?

  • LOL.... great answer man ur a genious

  • Hi,

    Yes you can use Like with Case

    Shabbir Muntakhab

Viewing 7 posts - 1 through 6 (of 6 total)

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