0

I Try to export the Query result per E-Mail as Attach

here the code:

DECLARE @Delimiter Char(1)

SET @Delimiter = CHAR(9)
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'MyProfile',
@recipients = 'myemailaad@mail.com',
@subject = 'Defects Total Value',
@body='MyText',
@query= 'MyQuery',
@attach_query_result_as_file=1,
@query_result_no_padding=1,
@Query_Result_Header = 1,
@query_attachment_filename = 'Results.xls',
@query_result_separator =@Delimiter

it work normally but I have two issues:

  1. The second row is empty : how deletet it(in the query)?

  2. In the Query i use : SET NOCOUNT ON, but in the xls file I can see the count (see screenshot), how deletet it(in the query)?

Thanks in advance

[[1]: https://i.stack.imgur.com/QPZlL.png][1]

Qsec
  • 11
  • 4

1 Answers1

0

the second issue is solved :no count in the result the "set NOCOUNT on; must be in the query and not only in the stored procedure. @Query='set NOCOUNT on;select....'

if the "SET NOCOUNT ON;" is only in the Sp like this:

   AS

   BEGIN

-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
  SET NOCOUNT ON;

it isn't enough to not returned the count

Qsec
  • 11
  • 4