This article is half-done without your Comment! *** Please share your thoughts via Comment ***
Check the below input data and expected output to split the string and generate a count of each string. Split the string by semi colon.
Input Data:
1 2 3 4 5 6 |
str1 -------------------- anvesh;dbrnd;blog dbrnd;blog dbrnd blog;anvesh |
Expected Output:
1 2 3 4 5 |
StringName StringCounts -------------------- ------------ anvesh 2 blog 3 dbrnd 3 |
Create a table with data:
1 2 3 4 5 6 7 8 9 |
CREATE TABLE tbl_SplitData ( str1 VARCHAR(20) ) GO INSERT INTO tbl_SplitData (str1) VALUES ('anvesh;dbrnd;blog'),('dbrnd;blog'),('dbrnd'),('blog;anvesh') GO |
Solution 1:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
SELECT StringName ,COUNT(*) StringCounts FROM ( SELECT CAST(CONCAT(' ) s CROSS apply ( SELECT ProjectData.D.value('.', 'VARCHAR(20)') as StringName FROM s.xmlcol.nodes('t') as ProjectData(D) )t GROUP BY t.StringName |
Please try the different solution for this puzzle and share it via comment...