SQL查询电子邮件附件 - 输出中有大量虚假数据

时间:2015-07-09 15:45:27

标签: sql sql-server

我将以下查询作为预定作业运行并将输出作为查询发送:

EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'SQL-Server',
@recipients = 'XXXXX',
@subject = 'Missing Essence File Check',
@query = N'SELECT *   FROM ([omnibus].[dbo].[OmniBus_CLP_Clips] CLP 
inner join [omnibus].[dbo].[OmniBus_CLD_ClipDetails] CLD on CLP.FLE_ID = CLD.FLE_ID) 
inner join [omnibus].[dbo].[OmniBus_FLE_Files] fle on clp.FLE_ID = fle.fle_id
where CLD_user_data  like '%.mov%'
and CLD_user_data  not like '%.m2v%'
and CLD_user_data  not like '%.wav%'
and fle.FLE_file_deleted = 0;',
@attach_query_result_as_file = 1,
@query_attachment_filename = 'Missing Essence File Check.txt'

当我在SQL Server Management Studio中执行此查询时,输出是一个包含8位数ID号的列表,或者是“没有受影响的行”的消息。当我将查询作为预定作业执行,然后使用数据库邮件通过电子邮件发送结果时,我获得了所有这些我不想要或不需要的额外数据。为什么所有这些附加信息都会出现在输出中?我怎么摆脱它?

*FLE_ID      CLP_clip_name                                                    CLP_clip_title                                                                                                                   CLT_ID      CLP_in_point CLP_out_point CLP_duratio
n CLP_duration_frames CLP_tc_format_id CLP_complexity CLP_Locations                                                                                                                                                                                             



rowversion CLP_WorkflowStatus   CLP_XTL                                                                                                                                                                                          
                                                                CLP_InheritanceEnabled FLE_ID      CLD_vision_duration CLD_audio_duration CLD_prog_start CLD_video_mode CLD_audio_mode CLD_video_trans CLD_audio_trans CLD_wipe_mode CLD_wipe_num CLD_quality CL
D_cache_mode CLD_logo    CLD_gpi     CLD_not_before CLD_not_after CLD_start_date          CLD_end_date            CLD_pdc     CLD_precompile CLD_archive_after CLD_delete_after CLD_suppress_logo CLD_size    CLD_version CLD_mirror  CLD_loop CLD_group_id CLD_
status  CLD_use_caption CLD_use_subtitle CLD_record  CLD_clip_unavailable CLD_cg_command CLD_cg_next_page CLD_cg_version CLD_speed   CLD_split   CLD_flags   CLD_pdc_type CLD_user_data_size CLD_subtitle_file                                                CL
D_cg_seq_flag CLD_source_format CLD_active_region CLD_user_data                                                                                                                                                                                                 
                                                   FLE_ID      FLE_external_key                                   FLE_sharer_path                                                                                                                  FLE_secondary
_path                                                                                                               DOM_ID      FLE_file_name                                                    FLE_file_title                                                 
FLE_file_cats                                                                                                                                                                                 

FLT_ID      SFT_ID      FLE_creator                      FLE_date_created        FLE_date_accessed       FLE_date_modified       FLE_file_deleted FLE_file_dustbinned FLE_keywords                       
                                                                                                                                                                                                                              FLE_timestamp FLE_protected FLE_co
ntents FLE_write_date          FLE_Synchronised FLE_unique_key                                                                                                                  
----------- ---------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------- ----------- ------------ ------------- -----------
- ------------------- ---------------- -------------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------ ---------- -------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------- ---------------------- ----------- ------------------- ------------------ -------------- -------------- -------------- --------------- --------------- ------------- ------------ ----------- --
------------ ----------- ----------- -------------- ------------- ----------------------- ----------------------- ----------- -------------- ----------------- ---------------- ----------------- ----------- ----------- ----------- -------- ------------ ----
------- --------------- ---------------- ----------- -------------------- -------------- ---------------- -------------- ----------- ----------- ----------- ------------ ------------------ ---------------------------------------------------------------- --
------------- ----------------- ----------------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------- ----------- -------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------- -------------
------------------------------------------------------------------------------------------------------------------- ----------- ---------------------------------------------------------------- ---------------------------------------------------------------
----------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------ ----------- ----------- -------------------------------- ----------------------- ----------------------- ----------------------- ---------------- ------------------- -----------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------- ------------- ------
------ ----------------------- ---------------- --------------------------------------------------------------------------------------------------------------------------------
(0 rows affected)*

1 个答案:

答案 0 :(得分:0)

您的查询以SELECT *开头,因此您将获得结果查询中所有表中的所有列。在管理工作室中单独运行完全相同的脚本不会显示任何不同的内容。

要解决该问题 - 只需在select语句中包含您感兴趣的列。

至于您的其他问题,请参阅sp_send_dbmail上的MSDN页面: - 我相信您在可选参数@query_result_header之后,它指定您希望输出中的列名称 - 您想要设置将它排除在0以外。

虽然我还没有尝试过,但我相信使用@exclude_query_output设置为0将排除“(0行受影响)”消息,但也排除了你所追求的查询的输出,所以只是删除该行计数消息,如果您不想包含该行,我建议您使用通常的SET NOCOUNT ON;预先处理您的查询。