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
Grasshopper
Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)

Group: General Forum Members
Points: 14 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
Grasshopper
Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)

Group: General Forum Members
Points: 14 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
Grasshopper
Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)

Group: General Forum Members
Points: 14 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
Grasshopper
Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)

Group: General Forum Members
Points: 14 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
SSC Veteran
SSC Veteran (257 reputation)SSC Veteran (257 reputation)SSC Veteran (257 reputation)SSC Veteran (257 reputation)SSC Veteran (257 reputation)SSC Veteran (257 reputation)SSC Veteran (257 reputation)SSC Veteran (257 reputation)

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

@query_result_separator=' '
oscar.leeper
oscar.leeper
Valued Member
Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)

Group: General Forum Members
Points: 55 Visits: 147
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
SSC-Enthusiastic
SSC-Enthusiastic (124 reputation)SSC-Enthusiastic (124 reputation)SSC-Enthusiastic (124 reputation)SSC-Enthusiastic (124 reputation)SSC-Enthusiastic (124 reputation)SSC-Enthusiastic (124 reputation)SSC-Enthusiastic (124 reputation)SSC-Enthusiastic (124 reputation)

Group: General Forum Members
Points: 124 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
Grasshopper
Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)

Group: General Forum Members
Points: 21 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