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.
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.
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)