Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

The below SQL strings together data

Status
Not open for further replies.

FranS37

Programmer
Jun 6, 2002
59
US
The below SQL strings together data from multiple rows, separated by a comma. I need to separate those values with carriage return. I can't make it work with suggestions I'm finding on the web. Any ideas?


SELECT DISTINCT p1.RequestLink,
CONVERT(VARCHAR(255),REPLACE((SELECT CONVERT(VARCHAR(30),ApprovalType) + ',' AS 'data()'
FROM Approval p2
WHERE p2.RequestLink = p1.RequestLink
AND (PersonLink IS NOT NULL)
ORDER BY p2.RequestLink
FOR XML PATH('')) + '$', ',$', '')) AS Type
FROM Approval p1
GROUP BY RequestLink
 
Try replacing ',' in

<pre>
CONVERT(VARCHAR(255),REPLACE((SELECT CONVERT(VARCHAR(30),ApprovalType) + ',' AS 'data()'
</pre>

with CHAR(13) or CHAR(13) + CHAR(10).

Tamar
 
Thank you for the response.

Your suggestions is one I found just doing an on line search, but got the below results:

CSR&#x0D; REQUEST&#x0D; CHECKLIST&#x0D; $

using

CONVERT(VARCHAR(255),REPLACE((SELECT CONVERT(VARCHAR(30),ApprovalType) + CHAR(13) + CHAR(10) AS 'data()'
 
&#x0D; is the way LF (CHAR(10)) is represented in HTML/XML. Have you tried displaying the result somewhere other than SSMS?

I guess a good question is what you want to do with this result.

Tamar
 
I've only viewed it in SSMS. I want to use the data in an SAP Business Objects report.

Thanks.
 
What did work was a Replace function in BI - replace commas with Char(13):

Replace ([fieldname];",";Char(13))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top