Finding occurence of value in a given string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SwapnilD
    New Member
    • Jan 2010
    • 41

    Finding occurence of value in a given string

    I have a column say acct_values holding values like "1,8,10,19,20,2 9,35,50,51"
    In a where clause if I have to check 9 in a acct_values column from above values. It gives a positive result becasue 19 and/or 29 contains 9. I have tried "Like/PatIndex/CharIndex" but none of it gives a correct result.
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    If you are sure that there are no spaces in between commas, find '%,9,%'.

    If there are spaces, remove those spaces before you search for the string pattern.

    Good Luck!!!


    ~~ CK

    Comment

    • SwapnilD
      New Member
      • Jan 2010
      • 41

      #3
      Thanks for your help, it was great but it does not work in situations where there are strings like "9", "1,2,9".

      However, I have acheived the goal through scripting and it is working fine.

      Comment

      • deepuv04
        Recognized Expert New Member
        • Nov 2007
        • 227

        #4
        this will help

        WHERE ',' + @String + ',' LIKE '%,' + acct_values + ',%'

        Comment

        Working...