Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Random Sorting of Delimited List Items with NEWID()

$
0
0

How do I get a random sort of the comma delimited colors?

SELECT   Subcategory = ps.[Name], 

         ColorList = Stuff((SELECT DISTINCT  ', ' + Color AS [text()] 

                            FROM AdventureWorks2012.Production.Product p 

                            WHERE p.ProductSubcategoryID = ps.ProductSubcategoryID

                            FOR XML PATH ('')),1,1,'') 

FROM     AdventureWorks2012.Production.ProductSubcategory ps

ORDER BY Subcategory; 

GO 
--  Black, Blue, Red


Kalman Toth Database & OLAP Architect IPAD SELECT Query Video Tutorial 3.5 Hours
New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012



Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>