My following query works and returns what I need.
But you can see that I am having to do a replace in the final select because FOR XML Path('') part has < and > instead of < and >
Any better way of handling this?
My code just seems like I'm cleaning things up instead of coding it correctly to start with.
;WITH cte (email, querystring) AS
querystring = LEFT(o.list, LEN(o.list)-1)
FROM #temp c
CONVERT(VARCHAR(MAX), querystring) + '<br />' AS [text()]
s.email = c.email
FOR XML PATH('')
) o (list))
2 AS CampaignTypeID,
FROM cte WHERE [dbo].[udf_Txt_IsEmail](email) = 1 GROUP BY email, querystring