Select column where only 4 digits in the raw,

  • Hi, all

    How can I do this in TSQL, there are alot of wild chars but I could not find how to count them, in case below I only want id =1 and 2

    this sql is not correct yet... just for idea

    THanks much

    Mar

    DECLARE

    @a VARCHAR(22) = ' alpha1234 qwerew', @b-2 VARCHAR(22) = '3456_Bravo', @C VARCHAR(22) = ' only_three123_Delta'

    --SELECT 1 id, @a c UNION select 2 id, @b-2 c UNION SELECT 3 id, @C c

    SELECT * FROM

    (SELECT 1 id, @a c UNION select 2 id, @b-2 c UNION SELECT 3 id, @C c) b

    WHERE c LIKE '%[1_3]%'

  • mario17 (6/25/2015)


    Hi, all

    How can I do this in TSQL, there are alot of wild chars but I could not find how to count them, in case below I only want id =1 and 2

    this sql is not correct yet... just for idea

    THanks much

    Mar

    DECLARE

    @a VARCHAR(22) = ' alpha1234 qwerew', @b-2 VARCHAR(22) = '3456_Bravo', @C VARCHAR(22) = ' only_three123_Delta'

    --SELECT 1 id, @a c UNION select 2 id, @b-2 c UNION SELECT 3 id, @C c

    SELECT * FROM

    (SELECT 1 id, @a c UNION select 2 id, @b-2 c UNION SELECT 3 id, @C c) b

    WHERE c LIKE '%[1_3]%'

    I'm not understanding what you want. Why do you want id = 1 and 2 but not 3?



    Alvin Ramard
    Memphis PASS Chapter[/url]

    All my SSC forum answers come with a money back guarantee. If you didn't like the answer then I'll gladly refund what you paid for it.

    For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • I think I figured out what you're looking for.

    Try changing the where clause to:

    WHERE c LIKE '%[0-9][0-9][0-9][0-9]%'



    Alvin Ramard
    Memphis PASS Chapter[/url]

    All my SSC forum answers come with a money back guarantee. If you didn't like the answer then I'll gladly refund what you paid for it.

    For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • Thanks ALvin!

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

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