simply need to send the output of a query as an email attachment. i can send it just fine (sp_send_dbmail), but the csv format is terrible. see here --
The values per record are like this: AA 100 -200 200 -2000 -400 400 2000 AAA 9
The export to csv mushes them all into one value, separating each with a '?', like this:
I've got numerous other jobs running just like this, sending csv attachments daily, without problem. I can't find the error in this.
Also, when trying to define the file with the datestamp, like this:
SET @file = 'D:\Reports\filename_'+con
It fails with this:
Msg 22051, Level 16, State 1, Line 0
Attachment file D:\Reports\filename.csv_20
Yet if I pull out the date, I write the file in just fine. (except that the output blows)
See my post below. The @query is formatted like that to allow for a header line in the output. When run in SSMS, the output is perfect, EXCEPT that I really need to order the symbols underneath the headerline. any ideas on how to do that?
Please and thank you, in advance.
DECLARE @file VARCHAR(100),
SET @file = 'D:\Reports\filename.csv'
SET @query = '
FROM view WHERE maxpos = ''maxpos''
FROM view WHERE maxpos <> ''maxpos''
ORDER BY ''maxpos'' DESC"
queryout "'+@file+'" -w -Sservername -T'
SET @subject = N'my subject - ' + CONVERT(NVARCHAR(11),GetDate(),121)
EXEC msdb.dbo.sp_send_dbmail @recipients ='me.com',
EXEC master..xp_cmdshell @query