Quantcast
Channel: Forum SQL Server Database Engine
Viewing all articles
Browse latest Browse all 15694

sp_send_dbmail csv attachement generating extra blank line between results

$
0
0

I have a query that I would like to email the results in a tab delimited csv so that it can be opened easily in excel.  When I run it in sp_send_dbmail as such:

exec msdb.dbo.sp_send_dbmail
@profile_name = 'MailProfile',
@Recipients= 'me@fake.com',
@Subject= 'YTD CSV',
@Body= 'CSV attached',
@query = 'set nocount on; select
cast(col1 as varchar(20)),
cast(col2 as varchar(20)),
cast(col3 as varchar(10)),
cast(col4 as varchar(8)),
cast(col5 as varchar(10)),
cast(col6 as varchar(20)),
cast(col7 as varchar(20)),
cast(col8 as  varchar(8)),
cast(col9 as varchar(8)),
cast(col10 as varchar(8)),
cast(col11 as varchar(8)),
cast(col12 as varchar(30))
from db.schema.table
where cast(colX as datetime) > ''2013-01-01''
order by cast(colX as datetime) desc;',
@execute_query_database = 'db',
@attach_query_result_as_file = 1,
@query_attachment_filename = 'ytd.csv',
@query_result_separator = '  ', --tab
@query_result_header = 0,
@query_result_no_padding = 1,
@exclude_query_output = 0; 

I get the results mostly as I want in an excel openable csv, but every other line is blank, creating a file thats twice as big as needed and that the consumers of the excel file find difficult and undesirable to deal with - like this:

552306221443407792013/04/3012:28:53TW - 1877340412800:00:0600:00:0000:00:0000:00:00[None]

552306386560348022013/04/3012:30:05CC - 2888716584700:01:2100:01:0000:00:0000:00:00[None]

552306477086719582013/04/3012:30:18CC - 2888716584700:00:1700:00:0000:00:4100:00:41[None]


I tried setting @query_result_no_padding to 0 and messing with @query_result_width but its the same result unless I set it too low and then the formatting is worse.   no_padding =1 seems to be what I want, but I'm not sure how to get rid of these extra blank lines.  I tried using comma delimited, same deal with the extra lines.  The only way I have been able to get a csv without extra blank lines is when I limit my query to 1 or 2 columns so I know it can be generated, just not sure how with my results.

Any help is greatly appreciated.  



Viewing all articles
Browse latest Browse all 15694

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>