how to attach multi queries result to different sheets‎ in same excel

  • @subject ='Status Log for Today'

    ,@profile_name ='Status'

    ,@query ='my query'

    ,@attach_query_result_as_file = 1

    ,@query_attachment_filename ='Status.csv'

    output has Column name called COUNTRY contain different countries AU,MY,SG

    I want to group by country and attach the result in different sheet in same excel file

    Example: If AU means all AU data in one sheet and SG means all SG data in another sheet

    Is it possible?

  • sandosh.star (2/12/2013)


    @subject ='Status Log for Today'

    ,@profile_name ='Status'

    ,@query ='my query'

    ,@attach_query_result_as_file = 1

    ,@query_attachment_filename ='Status.csv'

    output has Column name called COUNTRY contain different countries AU,MY,SG

    I want to group by country and attach the result in different sheet in same excel file

    Example: If AU means all AU data in one sheet and SG means all SG data in another sheet

    Is it possible?

    No, for multiple reasons. 1) a CSV file and an Excel file are two different things. While a file with a .csv extension may open in Excel by default because of a Windows setting on somone's workstation it does not make that file an Excel-formatted file. A CSV file is merely a special form of a plain-text file and cannot have "Tabs". 2) msdb.dbo.sp_send_dbmail cannot generate Excel files. It can generate text files with whatever name, extension and delimiter you like, but not Excel-formatted files. 3) msdb.dbo.sp_send_dbmail can only execute one query and push all the results from that query into a text file.

    If you must generate an Excel-formatted file by issuing multiple queries and pushing each result into a separate Worksheet within an Excel Workbook then you could look into using SSIS.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply