We have created a Job to sent mail with excel attachment. By fetching one of our table data into excel with some data ranges.
Now need some help to sent the email with multiple sheets excel attachment. Below have given my query part which us used currently with single sheet entry.
DECLARE @QUERY VARCHAR(MAX);
SET @QUERY = 'SET NOCOUNT ON SELECT * FROM dbo.TableName'
DECLARE @Subject NVARCHAR(MAX)
DECLARE @FILENAME NVARCHAR(MAX)
SET @Subject = 'Sending Mail With Excel Attachment'
SET @FILENAME='Excel Attachment.xlsx'
DECLARE @tab NCHAR(1) = CHAR(9)
EXEC msdb.dbo.sp_send_dbmail @profile_name='Tech Support',
@body = 'Test Mail for Sending Excel Attachment',
@query = @QUERY,
@query_result_separator = @tab,
@query_result_header = 1,
@attach_query_result_as_file = 1,
@query_attachment_filename = @FILENAME,
Please give me a solution to fix this with a modified query for multiple sheet attachment.