There is lots way to get the table from comma separate data by using the function to return table but I found the other way using XML path and using this you get better performance than another way while there are lots of data in a table. Even you get more time using function while to join with other tables so you can consider following example and fit your need and definitely you would get better performance and could enhance your query.
SELECT GroupID,ProductCode FROM ProductGroup
Now we can get result by run following query to get each ProductCode separately with GroupID as below:
SELECT GroupID, LTRIM(RTRIM(m.n.value('.','varchar(8000)'))) AS Code FROM ( SELECT GroupID,CAST('' + REPLACE(Code,',','') + '' AS XML) AS x FROM @t )t CROSS APPLY x.nodes('/XMLRoot/RowData')m(n)
Result that you want as below:
So finally the result with separate ProductCode with associated GroupID and now you can use this trick to join with other table to compare record by each ProductCode.