Another way is to use a string parsing UDF as below
;With Temp
AS
(
SELECT UserID,Email,ID,Name
FROM
(
SELECT u.UserID,u.Email,f.ID,f.Val
FROM User u
CROSS APPLY dbo.ParseValues(u.PublicationIDs,'|')f
)m
INNER JOIN Publication n
ON n.PublicationID = m.Val
)
SELECT UserID,Email,
STUFF((SELECT '|' + Name FROM Temp WHERE UserID = t.UserID AND Email = t.Email ORDER BY ID FOR XML PATH('')),1,1,'') AS PublicationNames
FROM (SELECT DISTINCT UserID,Email FROM Temp) t
ParseValues can be found here
http://visakhm.blogspot.in/2010/02/parsing-delimited-string.html
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs
No comments:
Post a Comment