﻿<?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)  / select order and comma delimited list / 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 05:36:51 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: select order and comma delimited list</title><link>http://www.sqlservercentral.com/Forums/Topic1419969-392-1.aspx</link><description>Thanks for that. Worked perfectly.</description><pubDate>Thu, 14 Feb 2013 07:09:59 GMT</pubDate><dc:creator>kevin 20860</dc:creator></item><item><title>RE: select order and comma delimited list</title><link>http://www.sqlservercentral.com/Forums/Topic1419969-392-1.aspx</link><description>Sample data: -[code="sql"]IF object_id('tempdb..#testEnvironment') IS NOT NULLBEGIN    DROP TABLE #testEnvironment;END;SELECT ID, NameINTO #testEnvironmentFROM (VALUES(1, 'Fred'),(2, 'Joe'),(3, 'Bob'))a(ID, Name);[/code]Query: -[code="sql"]DECLARE @Delimitedlist VARCHAR(8000) = '1,3,2';SELECT STUFF((SELECT ','+a.Name              FROM #testEnvironment a              INNER JOIN (SELECT ItemNumber AS Ordering, Item                          FROM dbo.DelimitedSplit8K(@Delimitedlist,',')                         ) b ON a.ID = b.Item              ORDER BY b.Ordering              FOR XML PATH(''), TYPE).value('.','NVARCHAR(MAX)'),1,1,'');[/code]Result: -[code="plain"]Fred,Bob,Joe[/code]dbo.DelimitedSplit8K function can be [url=http://www.sqlservercentral.com/articles/Tally+Table/72993/]found here --&amp;gt; http://www.sqlservercentral.com/articles/Tally+Table/72993/[/url].Solution will only work if your original deliminated string is never more than 8000 characters.</description><pubDate>Thu, 14 Feb 2013 04:58:44 GMT</pubDate><dc:creator>Cadavre</dc:creator></item><item><title>RE: select order and comma delimited list</title><link>http://www.sqlservercentral.com/Forums/Topic1419969-392-1.aspx</link><description>Sorry. The other one is in the wrong forum. I went back to delete it but there is no "delete" option. Should be in this forum only.thanks,</description><pubDate>Thu, 14 Feb 2013 04:31:10 GMT</pubDate><dc:creator>kevin 20860</dc:creator></item><item><title>RE: select order and comma delimited list</title><link>http://www.sqlservercentral.com/Forums/Topic1419969-392-1.aspx</link><description>tut tut tut.... don't cross-post Kevin! ;-)[url]http://www.sqlservercentral.com/Forums/Topic1419967-8-1.aspx[/url]</description><pubDate>Thu, 14 Feb 2013 04:29:14 GMT</pubDate><dc:creator>Abu Dina</dc:creator></item><item><title>select order and comma delimited list</title><link>http://www.sqlservercentral.com/Forums/Topic1419969-392-1.aspx</link><description>Hi all,Have an issue with a comma delimited list which is giving me a headache. Any suggestions would be appreciated.Delimited list 1,3,2I need to take each item from the list and match it to another table of names which in turn will be comma delimited. mytableID Name1 Fred2 Joe3 BobThe result I'm looking for is: Fred,Bob, JoeWhat's I've done is the following:declare @path varchar(100)select @path = '1,3,2'stuff((select name from mytable where id in (select id FROM dbo.ufn_split(path) for xml path('')),1,1,'')This works except that the "select ..where in " changes the order. Ie the names that are pulled from mytable are not in the same order as the id's in @path.For clarity if you break down my code to: select name from mytable where id in (select id FROM dbo.ufn_split(path)) it will give you a different order to this:select id FROM dbo.ufn_split(path)Any ideas?thanks</description><pubDate>Thu, 14 Feb 2013 04:28:10 GMT</pubDate><dc:creator>kevin 20860</dc:creator></item></channel></rss>