February 14, 2019 at 2:11 am
I have the following code to concatenate all distinct Aliasnaam per Masjien.
Snippet SELECT [Masjien], aliasname = STUFF((
SELECT N', ' + Aliasnaam FROM Oesskattings
WHERE [Masjien] = x.[Masjien]
FOR XML PATH(''), TYPE).value(N'.[1]', N'nvarchar(max)'), 1, 2, N'')
FROM Oesskattings AS x
GROUP BY [Masjien]
ORDER BY [Masjien];
However my Aliasnaam is NOT distinct and is added in the concatenation for every row.
I have tried, but cannot figure where to make Aliasnaam distinct.
Regards
February 14, 2019 at 3:28 am
gideon.e - Thursday, February 14, 2019 2:11 AMI have the following code to concatenate all distinct Aliasnaam per Masjien.Snippet Snippet SELECT [Masjien], aliasname = STUFF((
SELECT N', ' + Aliasnaam FROM Oesskattings
WHERE [Masjien] = x.[Masjien]
FOR XML PATH(''), TYPE).value(N'.[1]', N'nvarchar(max)'), 1, 2, N'')
FROM Oesskattings AS x
GROUP BY [Masjien]
ORDER BY [Masjien];
However my Aliasnaam is NOT distinct and is added in the concatenation for every row.
I have tried, but cannot figure where to make Aliasnaam distinct.
Regards
Kindly provide sample data with create and insert statement.
Saravanan
February 14, 2019 at 5:55 am
Hi Saravan. Thank you. Icannot figure out how to do that in Visual Studio Community 2015 with a local .mdf database.
February 14, 2019 at 6:12 am
Does it work if you put a DISTINCT in the SQL?SELECT [Masjien], aliasname = STUFF((
SELECT DISTINCT N', ' + Aliasnaam FROM Oesskattings
WHERE [Masjien] = x.[Masjien]
FOR XML PATH(''), TYPE).value(N'.[1]', N'nvarchar(max)'), 1, 2, N'')
FROM Oesskattings AS x
GROUP BY [Masjien]
ORDER BY [Masjien];
February 14, 2019 at 7:51 am
gideon.e - Thursday, February 14, 2019 5:55 AMHi Saravan. Thank you. Icannot figure out how to do that in Visual Studio Community 2015 with a local .mdf database.
Please see the article at the first link under "Helpful Links" in my signature line below for one way to do such a thing.
--Jeff Moden
Change is inevitable... Change for the better is not.
February 15, 2019 at 4:53 am
Jonathan AC Roberts - Thursday, February 14, 2019 6:12 AMDoes it work if you put a DISTINCT in the SQL?SELECT [Masjien], aliasname = STUFF((
SELECT DISTINCT N', ' + Aliasnaam FROM Oesskattings
WHERE [Masjien] = x.[Masjien]
FOR XML PATH(''), TYPE).value(N'.[1]', N'nvarchar(max)'), 1, 2, N'')
FROM Oesskattings AS x
GROUP BY [Masjien]
ORDER BY [Masjien];
Thank you Jonathan. Perfect.
February 15, 2019 at 4:56 am
Jeff Moden - Thursday, February 14, 2019 7:51 AMgideon.e - Thursday, February 14, 2019 5:55 AMHi Saravan. Thank you. Icannot figure out how to do that in Visual Studio Community 2015 with a local .mdf database.Please see the article at the first link under "Helpful Links" in my signature line below for one way to do such a thing.
Thank you Jeff. I will check it out and use in the future.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply