Если вы не храните эти значения бизнес-фокуса где-то еще в таблице, используйте CTE.
Схема:
CREATE TABLE #PartnerMaster (BusinessFocus VARCHAR(100), BusinessFocusNames VARCHAR(MAX))
INSERT INTO #PartnerMaster (BusinessFocus)
SELECT '1,2' UNION ALL SELECT '3' UNION ALL SELECT '2,3'
Теперь присоединитесь к Charindex
и сделайте их запятымиразделенный список с For XML Path
;WITH CTE AS(
SELECT '1' BusinessFocus, 'Product Videos' BusinessFocusNames
UNION ALL
SELECT '2' BusinessFocus, 'Installation Videos' BusinessFocusNames
UNION ALL
SELECT '3' BusinessFocus, 'Other Videos' BusinessFocusNames
)
SELECT P.BusinessFocus
, STUFF((SELECT ','+C.BusinessFocusNames FROM CTE C
WHERE CHARINDEX(C.BusinessFocus,P.BusinessFocus)>0
FOR XML PATH('')),1,1,'') AS BusinessFocusNames
FROM #PartnerMaster P
Результат:
+---------------+------------------------------------+
| BusinessFocus | BusinessFocusNames |
+---------------+------------------------------------+
| 1,2 | Product Videos,Installation Videos |
| 3 | Other Videos |
| 2,3 | Installation Videos,Other Videos |
+---------------+------------------------------------+