Introduction
This challenge involves counting the number of occurrences of HTML tags in a given list of strings. You can assume that there will be only valid HTML tags in the input strings. The output should display tags in ascending order.
Sample Data
ID HtmlText
-- ------------------------------------------------------------------------
1 <Html><Body><Font>This is challenge #18</Font><Font></Font></Body></Html>
Expected Results
ID TagNamesOccurance
-- --------------------------------------------------------------
1 Body(Found: 1 time), Font(Found: 2 times), Html(Found: 1 time)
Rules
- ID should be sorted in ascending order.
- The program should run in SQL SERVER 2005 and above.
- The output should be in the same way as it has been shown. Column names should be
exactly the same and the result must be sorted in Ascending order of ID.
Sample Script
Use the following script to generate the sample data.
DECLARE @t TABLE(ID INT IDENTITY, HtmlText VARCHAR(Max))
INSERT INTO @t(HtmlText)
SELECT '<Html><Body><Font>This is challenge #18</Font><Font></Font></Body></Html>'
SELECT * FROM @t
Restrictions
- The solution should be a single query that starts with a "SELECT" or “;WITH”.
Notes
Tags:Puzzles, TSQL Beginners Challenge, TC, TSQL Beginners Challenge 18