Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

sp_send_dbmail as CSV Expand / Collapse
Author
Message
Posted Wednesday, March 25, 2009 5:22 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, January 3, 2011 9:07 PM
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.
Post #683189
Posted Wednesday, March 25, 2009 5:25 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, January 3, 2011 9:07 PM
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.
Post #683192
Posted Wednesday, March 25, 2009 5:27 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, January 3, 2011 9:07 PM
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.
Post #683195
Posted Wednesday, March 25, 2009 5:29 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, January 3, 2011 9:07 PM
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.
Post #683198
Posted Wednesday, January 13, 2010 5:45 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Friday, March 4, 2011 7:49 AM
Points: 251, Visits: 11
Instead of using a space or double qoutes, use TAB

@query_result_separator=' '
Post #846812
Posted Tuesday, April 26, 2011 11:56 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, November 20, 2014 4:52 PM
Points: 35, Visits: 88
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

Post #1098882
Posted Monday, August 13, 2012 2:32 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Wednesday, April 30, 2014 8:51 AM
Points: 92, Visits: 393
@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.
Post #1344015
Posted Wednesday, June 25, 2014 8:59 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, September 24, 2014 3:22 PM
Points: 11, Visits: 69
So what do you use to specifiy a tab?
Post #1585950
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse