I have the following in a SQL select statement. It's purpose is to query a number of results and have them returned seperated by comma's.
SUBSTRING((
SELECT ', ' + s.jaopr
FROM jjops s
WHERE s.jajob = o.jajob
ORDER BY s.jaseq
FOR XML PATH('')
), 2, 1000)
I am getting the results I need, however the number of characters in each result varies from 2 characters to 5 characters. So extra spaces are returned in the results.
Example:
AA , AAA , BBBBB, BBBB , CCCCC
How can I change my substring so that there are not extra spaces when the returned result has less than 5 characters?
I think I understand what a Substring
is but I don't quite understand what the XML PATH
does, as I copied this when searching for a solution.