troubleshooting Question

Help with query that Counts and TRIMS values in a column

Avatar of Grayson Hampton
Grayson Hampton asked on
* T-SQLSQL
5 Comments1 Solution36 ViewsLast Modified:
I need to create a query that Counts the occurrences of BusinessSectorList to Name.
But, the values in BusinessSectorList have spaces and semi-colons.

The values in BusinessSectorList have the following 3 issues.

1. If there is a space (' Healthcare ') before or after the first value, remove it
2, If there is a space and semi-colon and another space ( ; Healthcare) before the first value, remove it.
3. If a semi-colon exist after the first value, remove it


Current Output Results:

BusinessSectorList                                                        Name
 Healthcare                                                                      Charlotte Spine Center
 ; Healthcare                                                                      Accolade, Inc.
Healthcare                                                                      Accolade, Inc.
Food;Wholesale                                                              The Schwan Food Company
Healthcare;Non-Profit                                                      12 and 12 Inc.



Desired Output Results:

BusinessSectorList                         Name                                                  Count
Healthcare                                       Charlotte Spine Center                     1
Healthcare                                       Accolade, Inc.                                     2
Healthcare                                        12 and 12 Inc.                                    1
Wholesale                                        The Schwan Food Company            1
ASKER CERTIFIED SOLUTION
Walter Ritzel
Senior Software Engineer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros