SQL server自动执行存储过程并返回执行的结果,该怎么处理

SQL server自动执行存储过程并返回执行的结果
希望完成的功能是:
       1. 每晚固定时间自动执行存储过程
       2. 执行完成后能返回执行的结果,并且将结果一邮件的方式发送到邮箱(重点)

       注:  这里说的执行结果,是执行的结果,不是执行是否成功。
                 
------解决方案--------------------
如果存储过程返回的记录不多的话,建议:首先要搭建好sql mail,然后写个作业job
步骤里面调用存储过程,其结果用变量保存起来后传给sp_send_dbmail
我的例子请参考:

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: 即将过试用期职员名单发邮件给HR经理、XX、XXX
-- =============================================
ALTER PROCEDURE [dbo].[usp_HR_TryMail]
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

DECLARE @AlertMails VARCHAR(4000)
SELECT @AlertMails=Rule_Value FROM dbo.Att_Rule WHERE Org_Id=3 AND Rule_No='AlertMails'
IF LTRIM(RTRIM(@AlertMails))<>'' --收件人不为空时
BEGIN
DECLARE @Names VARCHAR(4000)

/************************1、将过试用期职员 提前15天提醒****************************/
IF EXISTS(
select E.EmpName
FROM HR_Employee E (NOLOCK) 
WHERE E.InCumbency=1 and E.EmployeeType='职员' AND E.TryuseDate>=getdate() 
AND DATEDIFF(day,getdate(),E.TryuseDate)<=15)
BEGIN
SET @Names=(SELECT ','+t2.EmpName
FROM HR_Employee t2 (NOLOCK) 
WHERE t2.EmployeeType='职员' AND t2.InCumbency=1 and t2.TryuseDate>=getdate() 
AND DATEDIFF(day,getdate(),t2.TryuseDate)<=15
FOR XML PATH('')); 


SET @Names='各位好!

还有15天即将过试用期的职员名单如下:
    
'+STUFF(@Names,1,1,'')+'。

或者请登陆OA系统http://192.168.4.10:88查询,位置在【人事管理】==>【到期提醒】。

此为系统自动发送,请勿回信。'


EXEC msdb.dbo.sp_send_dbmail 
@profile_name='ASKProfile'
,@recipients=@AlertMails
,@subject='即将过试用期职员名单',@body=@Names
;
END

/***************************2、合同期满前45天提醒**********************/
IF EXISTS(
select E.EmpName
FROM HR_Employee e (NOLOCK)  
WHERE  e.InCumbency=1 
AND (
(datediff(day,getdate(),CustomItem7)<=45 and (CustomItem7>Getdate() OR ISNULL(CustomItem8,'')='' OR ISNULL(CustomItem9,'')=''))
OR 
(datediff(day,getdate(),CustomItem9)<=45 and (CustomItem9>Getdate() OR ISNULL(CustomItem10,'')='' OR ISNULL(CustomItem11,'')='')) 
OR 
(datediff(day,getdate(),CustomItem11)<=45 and CustomItem11>Getdate())
))
BEGIN
SET @Names=(select ','+E.EmpName+E.EmpNo
FROM HR_Employee e (NOLOCK)  
WHERE  e.InCumbency=1 
AND (
(datediff(day,getdate(),CustomItem7)<=45 and (CustomItem7>Getdate() OR ISNULL(CustomItem8,'')='' OR ISNULL(CustomItem9,'')=''))
OR 
(datediff(day,getdate(),CustomItem9)<=45 and (CustomItem9>Getdate() OR ISNULL(CustomItem10,'')='' OR ISNULL(CustomItem11,'')='')) 
OR 
(datediff(day,getdate(),CustomItem11)<=45 and CustomItem11>Getdate())

FOR XML PATH('') ); 

SET @Names='各位好!

还有45天劳动合同即将到期的名单如下:
    
'+STUFF(@Names,1,1,'')+'。

或者请登陆OA系统http://192.168.4.10:88查询,位置在【人事管理】==>【到期提醒】。

此为系统自动发送,请勿回信。'

EXEC msdb.dbo.sp_send_dbmail 
@profile_name='ASKProfile'
,@recipients=@AlertMails
,@subject='劳动合同期满前45天提醒',@body=@Names
END
END
END