For example, I have a query like below and I want to remove info/warning messages (like 1 rows affected
) and header's lines (like -------------
) rows from SQL output file. I can disable info/warning messages on SQLCMD with -m 1 -W
parameters but I want to do this with T-SQL. How can I do that?
DECLARE @tab char(1) = CHAR(9)
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'sqldba',
@from_address = 'DISPLAYNAME <[email protected]>' ,
@subject = 'SQL Instance Info' ,
@recipients = '[email protected];[email protected]',
@copy_recipients= '[email protected];[email protected]',
@body = 'Results on attachment',
@body_format = 'HTML',
@query = N'
SET ANSI_WARNINGS OFF
SET NOCOUNT ON
SELECT SERVERPROPERTY(''ServerName'') as ''Instance_Name'',
exc.local_net_address as ''IP_Address'', exc.local_tcp_port as ''Port''
FROM sys.dm_exec_connections exc
WHERE exc.session_id = @@SPID
',
@attach_query_result_as_file = 1,
@query_attachment_filename = 'InstanceInfo.csv',
@query_result_separator=@tab,
@query_result_width =32767,
@query_result_no_padding=1,
@exclude_query_output=1,
@query_result_header=1
Results seems like below:
Instance_Name IP_Address Port
------------- ---------- ----
HOSTNAME 123.456.789.0 1433
(1 rows affected)
It should be:
Instance_Name IP_Address Port
HOSTNAME 123.456.789.0 1433