Hi,
I have one existing view(with around 15 fields), in which I have to add few more fields from table called PI.
Now these fields have values like (55C4444F-D83B-4F96-A011-367A3755BA6C , F52388E2-485B-49DF-8534-FDF46D23F59E , 722432E1-F063-4CBD-B83D-1B97836E82953) 3 values comma separated.(Sometimes only one value and sometimes 4 or 5 or 7-8 depend on user has entered on web page)
Also I have another table called PHA and this tables has 2 fields Values and Name so I have to map this two tables based on VALUES fields and get Name from this PHA table and show in view and that also Comma separated.
So basically I have to Parse the PI table's Values field 1st, map it with PHA table to get Name and then Make it comma separated in that existing view.
To make fields comma separate I used below query,
(SELECT DISTINCT SUBSTRING(
(
SELECT ','+ PI.[Name] AS [text()]
FROM [DB].[dbo].[Table] PHA1
Inner Join [DB].[dbo].[Table] PI
ON PHA.[Value] = PI.[VALUE]
WHERE PHA1.PId =PHA2.PId and PHA1.CId = PHA2.CId
ORDER BY PHA1.PId
For XML PATH ('')
), 2, 1000)
FROM [DB].[dbo].[Table] PHA2
Inner Join [cSharpSite_profiles].[dbo].[PetAllergies] PA
Inner Join [DB].[dbo].[Table] PI
ON PHA.[Value] = PI.[VALUE]
) [Name]
Vicky