获取添加到审核表的最新记录并发送电子邮件

问题描述 投票:0回答:1

我正在尝试获取添加到审核表中的最新记录,并向我组织中的某些人员发送电子邮件,其中添加了添加的记录的详细信息,但不确定如何执行此操作。

我正在使用 Sharepoint SSRS 报告通过以下查询来显示数据 -

-- for records which have updated BUSTYPE
SELECT     Upper(caa.Comments) +' Record' 'SQLAction',c.BUS_TYPE AS CurrentBusType, caa.BUS_TYPE AS PrevBusType, caa.LastModified, c.CUSTOMERID, c.NAME, c.ADDRESS1, c.ADDRESS2, c.CITY, c.STATE, c.ZIP, 
FROM         CUSTOMER_Audit AS caa
 INNER JOIN  CUSTOMER AS c ON caa.CUSTOMERID = c.CUSTOMERID 
where ISNULL(caa.BUS_TYPE,'') != ISNULL(c.BUS_TYPE,'')
and ( ISNULL(caa.BUS_TYPE,'')='' or ISNULL(c.BUS_TYPE,'')='')
and ISNULL(c.BUS_TYPE,'')=''
and Datediff(dd,Convert(date,caa.LastModified), getdate())<=30 -- last 30 days filter

Union

-- for records which are deleted
SELECT     Upper(caa.Comments) +' Record' 'SQLAction','' AS CurrentBusType, caa.BUS_TYPE AS PrevBusType, caa.LastModified, caa.CUSTOMERID, caa.NAME, caa.ADDRESS1, caa.ADDRESS2, caa.CITY, caa.STATE, caa.ZIP, 
FROM         CUSTOMER_Audit AS caa
where caa.Comments like '%Deleted%'
and Datediff(dd,Convert(date,caa.LastModified), getdate())<=30
order by caa.LastModified desc

我如何才能只发送最后一条记录的电子邮件,这些记录是在上一封电子邮件发送一些记录之后添加的。

新电子邮件不应发送上一封电子邮件中已发送的更新/删除记录。

我尝试在 Sharepoint 中使用快照,但它正在发送具有已发送的相同记录的所有快照(以及新记录,如果有的话)。不知道我是否在那里做错了什么。

或者,我应该调整 SQL 查询以仅显示最新记录吗?但我该怎么做呢?

我的 SQL Server 是 2008 R2。

sql sql-server t-sql sharepoint reporting-services
1个回答
0
投票

一个非常简单的解决方案是创建一个表来记录报告上显示的最后一条记录,例如

CREATE TABLE dbo.ReportHistory (
    -- Following is a way to identify the report, could be plain text
    -- Could be the ID of the report in SSRS
  Report varchar(128)
  , LastIdQueried bigint
)

然后每次运行报告时都会更新此表。并假设您通过存储过程提取结果。

但是,这是有问题的,因为如果您从 SSRS 手动运行报告,而不通过电子邮件发送结果,您将不会收到有关结果的通知。

因此,在这种情况下,我倾向于创建自己的快照,在我选择的时间触发代理作业,然后显示此静态快照中的数据。我的这个快照方案(简化)是:

CREATE TABLE dbo.ReportInstance (
    Id bigint NOT NULL IDENTITY (1,1) PRIMARY KEY CLUSTERED,
    DateOfReportRun datetime2(0) NULL,
    -- Following is a way to identify the report, could be plain text
    -- Could be the ID of the report in SSRS
    Report varchar(128) NULL
);

CREATE TABLE dbo.ReportInstanceItem (
    Id bigint NOT NULL IDENTITY (1,1) NOT NULL PRIMARY KEY CLUSTERED,
    ReportInstance bigint NULL REFERENCES dbo.ReportInstance(Id),
    -- Store the ids from the target table which are part of this report
    RecordId bigint NULL
);
© www.soinside.com 2019 - 2024. All rights reserved.