I am creating a report to be send out daily. In one of the columns I have String of all of the Item numbers associated with the Sales Order (So one sales order to possibly multiple Item numbers). The Item numbers String is separated by ','s. To be able to do this I am using a Select statement where Order numbers are same, for XML PATH('') inside of a STUFF.
After I have generated this temp table of my data I am sending an email of the data out. I am using HTML formatting in a @mailmsg setting up the table and sending it. My problem is when the email is sent the column with all of the Item numbers are all on the same line and I need them to be soft returned onto a new line (but same cell).
I have attempted to use CHAR(10) and CHAR(13) in my STUFF function to no prevail.
Any suggestions? Below is my code for my stuff into my temp table:
UPDATE @SOTable
Set PODetails = STUFF( (
Select ', PONumber: ' + CAST(PONum AS VARCHAR),
', POQty: ' + CAST(POQty AS VARCHAR)
From @POTable
Where SONo = PONo
FOR XML PATH('')
),1, 1, '')
Then for my mail message, after I populate the table headers do this for the data:
CAST ((
select
(convert(varchar(8), SO.SONum)) as [TD align=center], '',
(CONVERT(varchar(8), SO.SOItmNo)) as [TD align=center], '',
td = (ltrim(rtrim(SO.SODesc))), '',
(convert(varchar(8), SO.SONSN)) as [TD align=center], '',
CONVERT(varchar(8), SO.SOSRNo)as [TD align=center], '',
convert(varchar(3), SO.SOSRQty)as [TD align=center], '',
convert(varchar(3), SO.SOUOM)as [TD align=center], '',
CAST(convert(varchar, SO.SODate, 101) AS VARCHAR) as [TD align=center], '',
td = SO.PODetails
from @SOTable SO
order by SO.SODate
for XML RAW('tr'), ELEMENTS
) as nvarchar(max))