Para seleccionar el texto entre CATEGORY=
y la primer ,
que le sigue (o hasta el final del texto):
CASE WHEN CHARINDEX('CATEGORY=',m.DESCRIPTION) > 0
THEN SUBSTRING(m.DESCRIPTION,
CHARINDEX('CATEGORY=',m.DESCRIPTION) + LEN('CATEGORY='),
CHARINDEX(',',m.DESCRIPTION+',',CHARINDEX('CATEGORY=',m.DESCRIPTION)+1) - CHARINDEX('CATEGORY=',m.DESCRIPTION) - LEN('CATEGORY=')
)
ELSE ''
END
Ejemplo:
+----+-----------------------------------------------+-------------+
| | DESCRIPTION | Resultado |
+----+-----------------------------------------------+-------------+
| 1 | ID=123444,CATEGORY=ABC,OTRO=#### | ABC |
| 2 | ID=123444,CATEGORY=ABCDEF,OTRO=####,MAS=GHIJK | ABCDEF |
| 3 | ID=123444,CATEGORY=A B C D E F,OTRO=#### | A B C D E F |
| 4 | ID=123444,CATEGORY=,OTRO=#### | |
| 5 | ID=123444,CATEGORY=ABC | ABC |
| 6 | ID=123444,CATEGORY=ABCDEF | ABCDEF |
| 7 | ID=123444,CATEGORY= | |
| 8 | CATEGORY=ABC,OTRO=#### | ABC |
| 9 | CATEGORY= | |
| 10 | ID=123444,OTRO=#### | |
| 11 | ABCDEF | |
+----+-----------------------------------------------+-------------+