Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 SQL sp_send_dbmail with csv attachment

Author  Topic 

IK1972

56 Posts

Posted - 2015-02-04 : 18:34:55
I have one table called stats where we collect the stats and top queries. I need to send report on regular basis for top queries.

I'm trying to send email with sp_send_dbmail with CSV file attached. Issue is in result set i have 8 columns and one column is with SQL Statement so it has comma and carriage returns so when I open the csv file its not display data properly.

Any idea how to fix this issue.

Thanks

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2015-02-04 : 19:30:25
Have you tried putting double quotes around your column that holds the SQL statement?



Those who will not reason, are bigots, those who cannot, are fools, and those who dare not, are slaves. -Lord Byron, poet (1788-1824)
Go to Top of Page

IK1972

56 Posts

Posted - 2015-02-04 : 20:49:52

Yes I try but its not working

quote:
Originally posted by Bustaz Kool

Have you tried putting double quotes around your column that holds the SQL statement?



Those who will not reason, are bigots, those who cannot, are fools, and those who dare not, are slaves. -Lord Byron, poet (1788-1824)

Go to Top of Page

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2015-02-05 : 01:49:31
An alternative is to use a Powershell script - which gives you the extra capacity of manipulating the output before it's added as an attachment.
For basic template on how to send an email through Powershell - http://www.sqlserver-dba.com/2012/01/sql-server-send-email-using-powershell.html

Jack Vamvas
--------------------
http://www.sqlserver-dba.com
Go to Top of Page

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2015-02-05 : 09:07:13
YOu need to post your code that calls sp_send_dbmail and any error messages you receive
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2015-02-05 : 12:09:52
Have you tried HTML format instead of CSV?

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -