This was the question from Pinal Dave's blog and i have answered the same. Thought this might be useful for my friends too and posting the same here. Hi, I’ve following problem, which I’ve not been able to do successfully. Your help will be appreciated. Table has following 2 columns DocNum DocEntry 1 234 2 324 2 746 3 876 3 764 4 100 4 387 Expected result is as follow 1 234 2 324, 746 3 876, 764 4 100, 387 Thanks Rahul Jain on August 16, 2010 at 12:22 pm | ReplySathya Narayanan Your comment is awaiting moderation. Hi Rahul Jain, Here is the answer : select distinct x.id ,substring( (select textfield + ‘,’ from testtable y where x.id=y.id order by x.Id for xml path(”)) ,0 ,LEN((select textfield + ‘,’ from testtable y where x.id=y.id order by x.Id for xml path(”)))) from testtable x Here is the output : 1 234 2 324,746 3 876,764 4 100,387 Thanks and Regards Sathya
This was the question from Pinal Dave's blog and i have answered the same. Thought this might be useful for my friends too and posting the same here.
Hi,
I’ve following problem, which I’ve not been able to do successfully. Your help will be appreciated.
Table has following 2 columns
DocNum DocEntry 1 234 2 324 2 746 3 876 3 764 4 100 4 387
Expected result is as follow
1 234 2 324, 746 3 876, 764 4 100, 387
Thanks Rahul Jain
Hi Rahul Jain,
Here is the answer :
select distinct x.id ,substring( (select textfield + ‘,’ from testtable y where x.id=y.id order by x.Id for xml path(”)) ,0 ,LEN((select textfield + ‘,’ from testtable y where x.id=y.id order by x.Id for xml path(”)))) from testtable x
Here is the output :
1 234 2 324,746 3 876,764 4 100,387
Thanks and Regards Sathya