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
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
1 -- these are your rows of data with a sort order of 1 to make sure they are situated below your column headings
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_attachment_filename = 'BOOK1.csv'
Hope this helps.