i have one SQL table
in which many records, i want to know how many names are in it and how much time one name in it.
Table NameMst
Name
john,smith,alax,rock
smith,alax,sira
john,rock
rock,sira
I want to find how much name are there and count of its.
expected output should be like this
Name Count
john 2
smith 2
alax 2
rock 3
sira 2
help me to resolved it.
You can extract the names using a recursive CTE and some string parsing. The rest is just aggregation:
As you have probably figured out, storing comma delimited lists in SQL Server is a bad idea. You should have an association/junction table with one row per name (and other columns describing the list it is in).
Result: