February 14, 2013 at 4:25 am
Sorry ignore this -- Should be in the sql 2008 forum
-----------------------------------
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,2
I need to take each item from the list and match it to another table of names which in turn will be comma delimited.
mytable
ID Name
1 Fred
2 Joe
3 Bob
The result I'm looking for is: Fred,Bob, Joe
What'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.
Any ideas?
thanks
February 14, 2013 at 7:58 am
The original thread is here. http://www.sqlservercentral.com/Forums/Topic1419969-392-1.aspx
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply