Thank you very much!
This function worked like a charm!
All that I needed to do was to write a WHILE loop that searches for the pattern in my string and isolate it in a separate var. Then I just ran the function against this var — and voilà! — I got my list!
To whose may interest here it is what I did:
DECLARE @mystring VARCHAR(MAX)
DECLARE @mycode VARCHAR(MAX)
DECLARE @allcodes VARCHAR(MAX)
DECLARE @found INT
SET @found = 0
SET @allcodes = ''
/* start selecting the contents from your table and loading into the @mystring var (input string) */
SELECT @mystring = from [YOURTABLE] where [YOUR CONDITION]
/* now it will scan the input string to find the codes /
WHILE (@found = 0)
BEGIN
/ pick the next code found using a custom Regex function /
SELECT @mycode = MyDatabase.dbo.regexObjMatch(@mystring,'[1-9][BCDEFHJKLNPRSGT][1-9]')
IF ((@mycode <> '') AND (@mycode IS NOT NULL))
BEGIN
/ add the code found to the @allcodes var */
SET @allcodes = @allcodes + @mycode + ','
/* remove the code from input string */
SET @mystring = RTRIM(REPLACE(@mystring,@mycode,''))
/* remove comma at the end of the input string if any */
WHILE (SUBSTRING(@mystring,LEN(@mystring),1) = ',')
SET @mystring = SUBSTRING(@mystring,1,LEN(@mystring)-1)
END
ELSE
/* no more codes found */
SET @found = 1
END
/* remove the comma at the end of @allcodes var */
IF (SUBSTRING(@allcodes,LEN(@allcodes),1) = ',')
SET @allcodes = SUBSTRING(@allcodes,1,LEN(@allcodes)-1)
/* run the function agains the @allcodes var */
select * from MyDatabase.dbo.DelimitedSplit8k (@allcodes,',')