﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2008 / T-SQL (SS2K8)  / Get distinct values into single column / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Fri, 24 May 2013 19:32:48 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Get distinct values into single column</title><link>http://www.sqlservercentral.com/Forums/Topic1421033-392-1.aspx</link><description>One possible modification that you might want to make is to change this:[code="sql"]d2.Color AS [text()][/code]to this:[code="sql"]d2.Color AS [data()][/code]That way your items would have a space between them instead of being run together in a continuous string.</description><pubDate>Wed, 20 Feb 2013 11:56:39 GMT</pubDate><dc:creator>buddy__a</dc:creator></item><item><title>RE: Get distinct values into single column</title><link>http://www.sqlservercentral.com/Forums/Topic1421033-392-1.aspx</link><description>[quote][b]dgowrij (2/19/2013)[/b][hr]Could you please clarify what the below statement actually does?[code="sql"].value('.[1]', 'varchar(MAX)')[/code]Especially the '.[1]'[/quote]The value XML method is documented in Books Online:[url]http://msdn.microsoft.com/en-us/library/ms178030.aspx[/url]The '.[1]' is an XQuery expression, where the '.' is a path expression containing an axis step and a node test:[url]http://msdn.microsoft.com/en-us/library/ms190451.aspx[/url]More precisely the '.' is approximate shorthand for the axis step and node test, self::node():[url]http://msdn.microsoft.com/en-us/library/ms191460.aspx[/url]The [1] is a predicate:[url]http://msdn.microsoft.com/en-us/library/ms177470.aspx[/url]The XML value method requires a single value as input, hence the technical need for the predicate [1].</description><pubDate>Tue, 19 Feb 2013 00:35:57 GMT</pubDate><dc:creator>Paul White</dc:creator></item><item><title>RE: Get distinct values into single column</title><link>http://www.sqlservercentral.com/Forums/Topic1421033-392-1.aspx</link><description>Thank you both, this is very helpful!</description><pubDate>Mon, 18 Feb 2013 06:54:09 GMT</pubDate><dc:creator>Triality</dc:creator></item><item><title>RE: Get distinct values into single column</title><link>http://www.sqlservercentral.com/Forums/Topic1421033-392-1.aspx</link><description>[url=http://sqlfiddle.com/#!3/3d695/44]SQLFiddle[/url] (link) showing the following solution:[code="sql"]DECLARE @Data AS TABLE(    StoreName   varchar(50) NOT NULL,    Category    varchar(50) NOT NULL,    Product     varchar(50) NOT NULL,    Color       varchar(50) NOT NULL,    PRIMARY KEY (StoreName, Category, Product, Color));INSERT @Data    (StoreName, Category, Product, Color)VALUES    ('My Store', 'Clothing', 'Awesome Shirt', 'White'),    ('My Store', 'Clothing', 'Awesome Shirt', 'Green'),    ('My Store', 'Clothing', 'Awesome Shirt', 'Blue'),    ('My Store', 'Cars', 'Chevy Impala', 'White'),    ('My Store', 'Cars', 'Chevy Impala', 'Black'),    ('My Store', 'Cars', 'Chevy Impala', 'Grey');[/code][code="sql"]SELECT    d.StoreName,    d.Category,    d.Product,    Colors =        (            SELECT                d2.Color AS [text()]            FROM @Data AS d2            WHERE                d2.StoreName = d.StoreName                AND d2.Category = d.Category                AND d2.Product = d.Product            ORDER BY                d2.Color            FOR XML                PATH (''), TYPE        ).value('.[1]', 'varchar(MAX)')FROM @Data AS dGROUP BY     d.StoreName,    d.Category,    d.ProductORDER BY    d.StoreName,    d.Category,    d.Product;[/code]</description><pubDate>Mon, 18 Feb 2013 02:34:44 GMT</pubDate><dc:creator>Paul White</dc:creator></item><item><title>RE: Get distinct values into single column</title><link>http://www.sqlservercentral.com/Forums/Topic1421033-392-1.aspx</link><description>try this link[url]http://sqlblog.com/blogs/adam_machanic/archive/2006/07/12/rowset-string-concatenation-which-method-is-best.aspx[/url]</description><pubDate>Mon, 18 Feb 2013 01:05:23 GMT</pubDate><dc:creator>BriPan</dc:creator></item><item><title>Get distinct values into single column</title><link>http://www.sqlservercentral.com/Forums/Topic1421033-392-1.aspx</link><description>Hi -I am having trouble writing a query to get the distinct values of a column grouping into a single column.  Please see the example below:[b][u]Data:[/u][/b]Store Name | Category | Product | ColorMy Store | Clothing | Awesome Shirt | WhiteMy Store | Clothing | Awesome Shirt | GreenMy Store | Clothing | Awesome Shirt | BlueMy Store | Cars | Chevy Impala | WhiteMy Store | Cars | Chevy Impala | BlackMy Store | Cars | Chevy Impala | Grey[b][u]Desired Result:[/u][/b]My Store | Clothing | Awesome Shirt | WhiteGreenBlueMy Store | Cars | Chevy Impala | WhiteBlackGreyThanks for your help!</description><pubDate>Sun, 17 Feb 2013 22:53:44 GMT</pubDate><dc:creator>Triality</dc:creator></item></channel></rss>