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
jo
SELECT y.Name, count(*) Count
FROM
(VALUES
('john,smith,alax,rock'),
('smith,alax,sira'),
('john,rock'),
('rock,sira')) x(names)
CROSS APPLY
(
SELECT t.c.value('.', 'VARCHAR(2000)') Name
FROM (
SELECT x = CAST('' +
REPLACE(x.names, ',', ' ') + ' ' AS XML)
) a
CROSS APPLY x.nodes('/t') t(c)
) y
GROUP BY y.Name
Result:
Name Count
alax 2
john 2
rock 3
sira 2
smith 2