Is there a way to use like with an array of values?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Vikki McCormick
    New Member
    • Aug 2010
    • 46

    Is there a way to use like with an array of values?

    Is there a more efficient way to write something like this? I have a text field that is updated by Sales people who will write, as an example, "This is opp 1" or "Call is Opportunity 12" or "opportunit y 5 - left message". It's totally free form. Reps have been instrusted to enter info a certain way, and simply will not receive the credit if they don't, but I do have to count data based on lower '%Opp%#%' in some way allow for human error to some extend.

    I am not sure how to do this efficiently, I have several different counts, and this does not seem like the best strategy.

    If I use a loop how do I group by rep?

    Code:
    select c.OwneridName as 'Sales Person'
    ,SUM (case when (lower(Subject) like 'opp%1%'
    or lower(Subject) like 'opp%2%'
    or lower(Subject) like 'opp%3%'
    or lower(Subject) like 'opp%4%'
    or lower(Subject) like 'opp%5%'
    or lower(Subject) like 'opp%6%'
    or lower(Subject) like 'opp%7%'
    or lower(Subject) like 'opp%8%'
    or lower(Subject) like 'opp%9%'
    or lower(Subject) like 'opp%10%'
    or lower(Subject) like 'opp%11%'
    or lower(Subject) like 'opp%12%'
    or lower(Subject) like 'opp%13%'
    or lower(Subject) like 'opp%14%'
    or lower(Subject) like 'opp%15%')THEN 1 ELSE 0 END) as [OPP CALLS]
    from  OpportunityTable as c 
    where c.actualend BETWEEN getdate()-1 AND getdate()
    group by c.OwnerIdName
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    What about
    Code:
    LIKE '%opp%[0-9]%'

    Comment

    • Vikki McCormick
      New Member
      • Aug 2010
      • 46

      #3
      Yes. That's it. Awesome. I just couldn't think of that today. I even looked at the bracket code. Thanks. : )

      Comment

      Working...