Click here to monitor SSC
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 Rookie
SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)

Group: General Forum Members
Points: 34 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
Valued Member
Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)

Group: General Forum Members
Points: 63 Visits: 160
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 Rookie
SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)

Group: General Forum Members
Points: 34 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-Enthusiastic
SSC-Enthusiastic (129 reputation)SSC-Enthusiastic (129 reputation)SSC-Enthusiastic (129 reputation)SSC-Enthusiastic (129 reputation)SSC-Enthusiastic (129 reputation)SSC-Enthusiastic (129 reputation)SSC-Enthusiastic (129 reputation)SSC-Enthusiastic (129 reputation)

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

Group: General Forum Members
Points: 18 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
SSChampion
SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)

Group: General Forum Members
Points: 11044 Visits: 14858
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
Grasshopper
Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)

Group: General Forum Members
Points: 18 Visits: 158
Tahnk you Jack that worked.
spin
spin
SSC-Enthusiastic
SSC-Enthusiastic (142 reputation)SSC-Enthusiastic (142 reputation)SSC-Enthusiastic (142 reputation)SSC-Enthusiastic (142 reputation)SSC-Enthusiastic (142 reputation)SSC-Enthusiastic (142 reputation)SSC-Enthusiastic (142 reputation)SSC-Enthusiastic (142 reputation)

Group: General Forum Members
Points: 142 Visits: 534
just stumbled across this thread. worked a treat thanks.
WILLIAM MITCHELL
WILLIAM MITCHELL
SSCommitted
SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)

Group: General Forum Members
Points: 1660 Visits: 3023
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