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


Can DatabaseMail attach a formatted Excel file?


Can DatabaseMail attach a formatted Excel file?

Author
Message
newbie_sql
newbie_sql
SSC Veteran
SSC Veteran (212 reputation)SSC Veteran (212 reputation)SSC Veteran (212 reputation)SSC Veteran (212 reputation)SSC Veteran (212 reputation)SSC Veteran (212 reputation)SSC Veteran (212 reputation)SSC Veteran (212 reputation)

Group: General Forum Members
Points: 212 Visits: 35
Hi

As per above suggestions, I tried to use tab as a query separator but still all the query data is coming in the same column..Is there something that I doing wrong??

EXEC msdb.dbo.sp_send_dbmail
@recipients=N'cv@xx.co.uk',
@body= 'Please find attached',
@subject = 'Test Email from SQL Server',
@profile_name ='DBMailProfile' ,
@query = 'exec uat.dbo.csp_Report 1,1',
@attach_query_result_as_file = 1 ,
@query_result_separator = ' ',
@query_result_no_padding = 1,
@query_result_header =0,
@query_attachment_filename = 'report.csv';

Im quite stuck here as all query data is coming as one row without column separation

Thanks
adam-639168
adam-639168
Old Hand
Old Hand (332 reputation)Old Hand (332 reputation)Old Hand (332 reputation)Old Hand (332 reputation)Old Hand (332 reputation)Old Hand (332 reputation)Old Hand (332 reputation)Old Hand (332 reputation)

Group: General Forum Members
Points: 332 Visits: 168
charu.verma (12/1/2009)
Hi

As per above suggestions, I tried to use tab as a query separator but still all the query data is coming in the same column..Is there something that I doing wrong??

EXEC msdb.dbo.sp_send_dbmail
@recipients=N'cv@xx.co.uk',
@body= 'Please find attached',
@subject = 'Test Email from SQL Server',
@profile_name ='DBMailProfile' ,
@query = 'exec uat.dbo.csp_Report 1,1',
@attach_query_result_as_file = 1 ,
@query_result_separator = ' ',
@query_result_no_padding = 1,
@query_result_header =0,
@query_attachment_filename = 'report.csv';

Im quite stuck here as all query data is coming as one row without column separation

Thanks


Did you make sure that there is a tab space between the quotes?

When I do it, there is a marked space like ' '
newbie_sql
newbie_sql
SSC Veteran
SSC Veteran (212 reputation)SSC Veteran (212 reputation)SSC Veteran (212 reputation)SSC Veteran (212 reputation)SSC Veteran (212 reputation)SSC Veteran (212 reputation)SSC Veteran (212 reputation)SSC Veteran (212 reputation)

Group: General Forum Members
Points: 212 Visits: 35
Its a 100% tab & not a spcae between quotes..still all data is coming in one column separated by a space,whereas I want each column of the result query to come in a separate column of the excel
DougGifford
DougGifford
SSC-Addicted
SSC-Addicted (439 reputation)SSC-Addicted (439 reputation)SSC-Addicted (439 reputation)SSC-Addicted (439 reputation)SSC-Addicted (439 reputation)SSC-Addicted (439 reputation)SSC-Addicted (439 reputation)SSC-Addicted (439 reputation)

Group: General Forum Members
Points: 439 Visits: 860
Maybe this will work?
@query_result_separator = char(9)

"When in danger or in doubt. Run in circles, scream and shout!" TANSTAAFL
"Robert A. Heinlein"
franciscom
franciscom
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 3
Thanks a lot, TAB resolved my issue!
TurnerC
TurnerC
Valued Member
Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)

Group: General Forum Members
Points: 52 Visits: 158
Hello,

I have followed the advise on the post for the following and have place a 'tab' in the query_result_seperator and the csv file is still opening incorrectly.

I would just like to verify that I place a ' then hit the TAB key and close with '
Any help would be appreciate. [I am running EXCEL version 2007 , SQL Server 2008]
Code:
exec msdb.dbo.sp_send_dbmail @recipients = '@.org;@.net;',
@body = 'Here are the visits :',
@query = 'exec usp_nh_PharamacyInterventionExport',
@query_attachment_filename = 'results.csv',
@query_result_separator = ' ',
@subject = 'Payors Changed Yesterday',
@query_result_header = 1,
@attach_query_result_as_file = 1,
@execute_query_database = 'it'

thank you
Jack Corbett
  Jack Corbett
SSC-Forever
SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)

Group: General Forum Members
Points: 45229 Visits: 14925
Try using CHAR(9) instead of using a TAB from the Keyboard, like Doug suggested a few posts earlier.



Jack Corbett

Applications Developer

Don't let the good be the enemy of the best. -- Paul Fleming
At best you can say that one job may be more secure than another, but total job security is an illusion. -- Rod at work

Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
TurnerC
TurnerC
Valued Member
Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)

Group: General Forum Members
Points: 52 Visits: 158
Tahnk you Jack that worked.
spin
spin
Mr or Mrs. 500
Mr or Mrs. 500 (598 reputation)Mr or Mrs. 500 (598 reputation)Mr or Mrs. 500 (598 reputation)Mr or Mrs. 500 (598 reputation)Mr or Mrs. 500 (598 reputation)Mr or Mrs. 500 (598 reputation)Mr or Mrs. 500 (598 reputation)Mr or Mrs. 500 (598 reputation)

Group: General Forum Members
Points: 598 Visits: 537
just stumbled across this thread. worked a treat thanks.
WILLIAM MITCHELL
WILLIAM MITCHELL
Hall of Fame
Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)

Group: General Forum Members
Points: 3924 Visits: 3085
I had a similar problem exporting a CSV file from SSRS, where Excel would open the file as a single column. Turned out that the default SSRS export encoding for CSV was unicode, and Excel did not know how to handle that. I found the "Render" section in rsreportserver.config where you can override the encoding - set it to ASCII and that fixed my problem.

Not exactly the same as the OP's issue but hopefully this will help somebody.
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