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
worachek
worachek
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 226
Thanks, Ted!
scott_lotus
scott_lotus
SSC Veteran
SSC Veteran (288 reputation)SSC Veteran (288 reputation)SSC Veteran (288 reputation)SSC Veteran (288 reputation)SSC Veteran (288 reputation)SSC Veteran (288 reputation)SSC Veteran (288 reputation)SSC Veteran (288 reputation)

Group: General Forum Members
Points: 288 Visits: 395
Hi, would it be possible to post the full script you got working please. Thank you.
cdove
cdove
Valued Member
Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)

Group: General Forum Members
Points: 51 Visits: 69
I'd like to see the script too. Trying to get a tab delimiter to work. the char(9) doesn't work
Lavanyasri
Lavanyasri
SSC Eights!
SSC Eights! (945 reputation)SSC Eights! (945 reputation)SSC Eights! (945 reputation)SSC Eights! (945 reputation)SSC Eights! (945 reputation)SSC Eights! (945 reputation)SSC Eights! (945 reputation)SSC Eights! (945 reputation)

Group: General Forum Members
Points: 945 Visits: 955
Thanks a lot. it worked for me also.

But still i am getting ------ one complete row after the header columns
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
Lavanyasri (11/30/2015)
Thanks a lot. it worked for me also.

But still i am getting ------ one complete row after the header columns



I started this thread years ago - brings back memories hehe w00t

Funny, I just updated a query to fix this very issue you mentioned.

Step 1: Prepare a table with your data AND a single row that will become your column headings (using UNION ALL), as follows:


create table temptbl(ACCOUNT VARCHAR(15),FACILITY VARCHAR(255),SORTORDER INT)
insert into temptbl(account,facility,sortorder)
SELECT 'ACCOUNT','FACILITY',0 -- these will be your column headings
UNION ALL
SELECT
ACCOUNT,
FACILITY,
1 -- these are your rows of data with a sort order of 1 to make sure they are situated below your column headings
FROM someothertbl



Then in your database mail code, remove the automatic headings, because those come with the annoying dashes row that you're wanting to get rid of and populate your file making sure its sorted by SORTORDER:


@profile_name = 'YOURPROFILE',
@recipients = 'YOUR EMAIL ADDRESSES',
@subject = 'SUBJECT',
@query = 'set nocount on;SELECT account,facility FROM TEMPTBL order by sortorder',
@attach_query_result_as_file = 1,
@query_result_separator = ' ' ,
@query_result_no_padding = 1,
@query_result_header =0,
@query_attachment_filename = 'BOOK1.csv'



Hope this helps.
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