Link to home
Start Free TrialLog in
Avatar of VBdotnet2005
VBdotnet2005Flag for United States of America

asked on

return results in one string

My query returns a results like below.

select itemno from mytable where itemno between 9813 and 9865.

result :

9813
9814
9815
etc...

Can it be returned in one string with comma like below?

9813, 9814, 9815, etc
ASKER CERTIFIED SOLUTION
Avatar of Vikas Garg
Vikas Garg
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@PortletPaul: beat you by exactly 14 seconds
@chaau, yes, so I see, too much fussing with the format at my end :)
I wish MSSQL had an easy to use GROUP_CONCAT() function like MySQL. :)
or LISTAGG() in Oracle

I agree with you. The syntax of stuff() plus "for xml path" is a bit tedious and a bit tricky.
(Hence my fixation with formatting it :)
Concat_ws is better in my opinion. Works in Oracle and MySQL
I wish MSSQL had an easy to use GROUP_CONCAT() function like MySQL. :)
You have a couple of options:
1. Use CLR to build your own.  It is not difficult and can be more flexible.
2. Be patient. :)