Group By using partial text

I want to group records based on a column where the date is nearly the same, but not quite.    For example, suppose I have these record where the data is in a single column called "subject".  

I want to know how many or each "type" of records there are, i.e., 3 of "Case Assigned to", 2 of  "In home services case" and 4 of "Action: Case No."

Case Assigned to george
Case Assigned to mark
Case Assigned to mary
In home services case #1234
In home services case #5555
Action: Case No. 277534, jones
Action: Case No. 444534, smith
Action: Case No. 456789, Hall
Action: Case No. 90022, colbert
LVL 1
HLRosenbergerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

typetoitCommented:
You could use the Left command in SQL.  Then you should index that column for faster response if you are going to run this query multiple times.  A better way would be for each record to have a subjectID which would relate to "Case Assigned", "In home services", and "Action: Case No."
0
HLRosenbergerAuthor Commented:
It's a one time thing.
0
typetoitCommented:
Then use the left command such as Group by Left(subject, 12)
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Scott PletcherSenior DBACommented:
GROUP BY
SELECT LEFT(subject, CASE
    WHEN subject LIKE 'Case Assigned to%' THEN LEN('Case Assigned to')
    WHEN subject LIKE 'In home services case%' THEN LEN('In home services case')
    WHEN subject LIKE 'Action: Case No.%' THEN LEN('Action: Case No.')
    ELSE 20 END) AS category,
    ...
FROM table_name
GROUP BY LEFT(subject, CASE
    WHEN subject LIKE 'Case Assigned to%' THEN LEN('Case Assigned to')
    WHEN subject LIKE 'In home services case%' THEN LEN('In home services case')
    WHEN subject LIKE 'Action: Case No.%' THEN LEN('Action: Case No.')
    ELSE 20 END)
0
chuang4630Commented:
Group BY Left is a obviously a clear choice
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
HLRosenbergerAuthor Commented:
thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.