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
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
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
SSCarpal Tunnel
SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)

Group: General Forum Members
Points: 4272 Visits: 2614
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-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: 45159 Visits: 14925
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

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
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
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
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
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
Grasshopper
Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)

Group: General Forum Members
Points: 16 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
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
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
SSC Rookie
SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)

Group: General Forum Members
Points: 31 Visits: 12
This worked for me too!
Asim-16932
Asim-16932
Valued Member
Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)

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



den_maxi
den_maxi
Grasshopper
Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)

Group: General Forum Members
Points: 19 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