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
adam-639168
adam-639168
Right there with Babe
Right there with Babe (772 reputation)Right there with Babe (772 reputation)Right there with Babe (772 reputation)Right there with Babe (772 reputation)Right there with Babe (772 reputation)Right there with Babe (772 reputation)Right there with Babe (772 reputation)Right there with Babe (772 reputation)

Group: General Forum Members
Points: 772 Visits: 174
I have the following SP that will email me an attachment of the results of a specific query:

EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'PROFILE',
@recipients = 'MY@EMAILADDRESS',
@query = 'EXEC USP_SP',
@subject = 'DATA',
@attach_query_result_as_file = 1,
@query_result_separator ='' ,
@query_result_no_padding = 1,
@query_result_header =0,
@query_attachment_filename = 'ACCESS.XLS';


When I open the attachment obviously each data element is separated by a space but all elements are in 1 column. Is there a way to separate each element into its own column?

Thanks in advance for your help.

Adam
TheRedneckDBA
TheRedneckDBA
SSCrazy Eights
SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)

Group: General Forum Members
Points: 8324 Visits: 2634
Have you tried playing with the @query_result_separator? Perhaps make it a space or comma instead of an empty string?

The Redneck DBA
Jack Corbett
  Jack Corbett
SSC Guru
SSC Guru (103K reputation)SSC Guru (103K reputation)SSC Guru (103K reputation)SSC Guru (103K reputation)SSC Guru (103K reputation)SSC Guru (103K reputation)SSC Guru (103K reputation)SSC Guru (103K reputation)

Group: General Forum Members
Points: 103082 Visits: 15045
Because you are naming the file with an "XLS" extension, Excel thinks it is a native file and is not looking for a delimiter.

I would use "," for a delimiter and use a "CSV" extension on the file, then Excel will recognize it as a delimited file and because it is a csv, should open it in the correct manner.



Jack Corbett
Consultant Straight Path Solutions
Dont 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 QuestionHow 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
adam-639168
adam-639168
Right there with Babe
Right there with Babe (772 reputation)Right there with Babe (772 reputation)Right there with Babe (772 reputation)Right there with Babe (772 reputation)Right there with Babe (772 reputation)Right there with Babe (772 reputation)Right there with Babe (772 reputation)Right there with Babe (772 reputation)

Group: General Forum Members
Points: 772 Visits: 174
Jack Corbett (2/29/2008)
Because you are naming the file with an "XLS" extension, Excel thinks it is a native file and is not looking for a delimiter.

I would use "," for a delimiter and use a "CSV" extension on the file, then Excel will recognize it as a delimited file and because it is a csv, should open it in the correct manner.


Thanks Jack. I did what you said and the file is delimited by commas but still all in the same column. I can open it in Excel but I have to go through the process of telling Excel to separate the comma delimited values.

I'd really like this to be good to go when you open the attachment file.

Thanks, Adam.
adam-639168
adam-639168
Right there with Babe
Right there with Babe (772 reputation)Right there with Babe (772 reputation)Right there with Babe (772 reputation)Right there with Babe (772 reputation)Right there with Babe (772 reputation)Right there with Babe (772 reputation)Right there with Babe (772 reputation)Right there with Babe (772 reputation)

Group: General Forum Members
Points: 772 Visits: 174
Jason Shadonix (2/29/2008)
Have you tried playing with the @query_result_separator? Perhaps make it a space or comma instead of an empty string?


I have, and the data rows are still squashed into one column but delimited by a space or other characters (I tried using a "|" but no good either).

Thanks,
Adam.
Ted Walsh-457325
Ted Walsh-457325
SSC Rookie
SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)

Group: General Forum Members
Points: 38 Visits: 29
I have had similar problems with attaching an Excel (*.cvs) file and having the columns separated correctly.

We have received a solution that works for us. Use @query_result_separator = ' ' (this is a TAB between the ' ' )). It has worked for all of the problematic emails that we have had.

I hope it works for you as well.

thanks,
Ted
adam-639168
adam-639168
Right there with Babe
Right there with Babe (772 reputation)Right there with Babe (772 reputation)Right there with Babe (772 reputation)Right there with Babe (772 reputation)Right there with Babe (772 reputation)Right there with Babe (772 reputation)Right there with Babe (772 reputation)Right there with Babe (772 reputation)

Group: General Forum Members
Points: 772 Visits: 174
great! the tab between the ' ' works perfectly.

I had long since given up on this thread. Thanks for the solution.

Adam.



Ted Walsh (5/27/2008)
I have had similar problems with attaching an Excel (*.cvs) file and having the columns separated correctly.

We have received a solution that works for us. Use @query_result_separator = ' ' (this is a TAB between the ' ' )). It has worked for all of the problematic emails that we have had.

I hope it works for you as well.

thanks,
Ted

ben.weiner
ben.weiner
Valued Member
Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)

Group: General Forum Members
Points: 61 Visits: 12
This worked for me too!
Asim-16932
Asim-16932
SSC-Enthusiastic
SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)

Group: General Forum Members
Points: 156 Visits: 20
Me too, thanks!



den_maxi
den_maxi
SSC Rookie
SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)

Group: General Forum Members
Points: 27 Visits: 38
TAB for csv worked perfectly. Thanks!
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