Home > other >  Get the latest record added to an audit table and send email
Get the latest record added to an audit table and send email

Time:11-05

I am trying to get the latest record which is added to an audit table and send an email to some people in my organisation with the details of the record added but not sure how to do this.

I am using Sharepoint SSRS report to show the data using the following query -

-- 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 '           
  • Related