SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


sp_send_dbmail as CSV


sp_send_dbmail as CSV

Author
Message
Chris Maloney
Chris Maloney
SSC-Enthusiastic
SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)

Group: General Forum Members
Points: 154 Visits: 36
Yisaacs,
I am persisting with exactly the same problem and running into the same brick walls you are.
Trawling the internet suggests that it seems to work in some environments and not in others.
I've tried csv/xml with variations on all the switches.
I either get an attachment with most of the output truncated or all in one column like you or some rubbish hex data.
On their own, the queries are fine. Whack them into sp_send_dbmail and you enter the secret society of SQL mail programmers. Someone has the answer, but ain't telling. :-)
Chris Maloney
Chris Maloney
SSC-Enthusiastic
SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)

Group: General Forum Members
Points: 154 Visits: 36
Yisaacs,
I am persisting with exactly the same problem and running into the same brick walls you are.
Trawling the internet suggests that it seems to work in some environments and not in others.
I've tried csv/xml with variations on all the switches.
I either get an attachment with most of the output truncated or all in one column like you or some rubbish hex data.
On their own, the queries are fine. Whack them into sp_send_dbmail and you enter the secret society of SQL mail programmers. Someone has the answer, but ain't telling. :-)
Chris Maloney
Chris Maloney
SSC-Enthusiastic
SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)

Group: General Forum Members
Points: 154 Visits: 36
Yisaacs,
I am persisting with exactly the same problem and running into the same brick walls you are.
Trawling the internet suggests that it seems to work in some environments and not in others.
I've tried csv/xml with variations on all the switches.
I either get an attachment with most of the output truncated or all in one column like you or some rubbish hex data.
On their own, the queries are fine. Whack them into sp_send_dbmail and you enter the secret society of SQL mail programmers. Someone has the answer, but ain't telling. :-)
Chris Maloney
Chris Maloney
SSC-Enthusiastic
SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)

Group: General Forum Members
Points: 154 Visits: 36
Yisaacs,
I am persisting with exactly the same problem and running into the same brick walls you are.
Trawling the internet suggests that it seems to work in some environments and not in others.
I've tried csv/xml with variations on all the switches.
I either get an attachment with most of the output truncated or all in one column like you or some rubbish hex data.
On their own, the queries are fine. Whack them into sp_send_dbmail and you enter the secret society of SQL mail programmers. Someone has the answer, but ain't telling. :-)
adrabinski
adrabinski
Old Hand
Old Hand (339 reputation)Old Hand (339 reputation)Old Hand (339 reputation)Old Hand (339 reputation)Old Hand (339 reputation)Old Hand (339 reputation)Old Hand (339 reputation)Old Hand (339 reputation)

Group: General Forum Members
Points: 339 Visits: 11
Instead of using a space or double qoutes, use TAB

@query_result_separator=' '
oscar.leeper
oscar.leeper
SSC-Enthusiastic
SSC-Enthusiastic (111 reputation)SSC-Enthusiastic (111 reputation)SSC-Enthusiastic (111 reputation)SSC-Enthusiastic (111 reputation)SSC-Enthusiastic (111 reputation)SSC-Enthusiastic (111 reputation)SSC-Enthusiastic (111 reputation)SSC-Enthusiastic (111 reputation)

Group: General Forum Members
Points: 111 Visits: 148
Found this thread trolling for answers to the same question. Here's what works for me.

exec msdb.dbo.sp_send_dbmail
@profile_name = 'YOUR_PROFILE',
@Recipients= 'YOUR_EMAIL',
@Subject= 'sample message with attached query',
@Body= 'sample message with attached query',
@query = 'set nocount on select top 10 * from sys.tables',
@attach_query_result_as_file = 1,
@query_attachment_filename = 'sample.csv',
@query_result_separator = ',',
@query_result_header = 0,
@query_result_no_padding = 1,
@exclude_query_output = 1
scott_lotus
scott_lotus
SSChasing Mays
SSChasing Mays (654 reputation)SSChasing Mays (654 reputation)SSChasing Mays (654 reputation)SSChasing Mays (654 reputation)SSChasing Mays (654 reputation)SSChasing Mays (654 reputation)SSChasing Mays (654 reputation)SSChasing Mays (654 reputation)

Group: General Forum Members
Points: 654 Visits: 395
@query_result_separator=' ', (i.e TAB between quotation marks)

Thanks you so much , this worked for me . Simply cut and paste in today my query and BING , i get correct CSV files at last. :-D
cdove
cdove
SSC-Enthusiastic
SSC-Enthusiastic (149 reputation)SSC-Enthusiastic (149 reputation)SSC-Enthusiastic (149 reputation)SSC-Enthusiastic (149 reputation)SSC-Enthusiastic (149 reputation)SSC-Enthusiastic (149 reputation)SSC-Enthusiastic (149 reputation)SSC-Enthusiastic (149 reputation)

Group: General Forum Members
Points: 149 Visits: 69
So what do you use to specifiy a tab?
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search