spEmail_QueryActivity

Parameters

Parameter Parameter Type Mode Description
@BeginDate datetime IN
@EndDate datetime IN
@EmailType int IN
@RowCount int IN

Definition

Copy
CREATE PROCEDURE [dbo].[spEmail_QueryActivity]

    @BeginDate datetime,
    @EndDate datetime,
    @EmailType int,
    @RowCount int

AS

SET ROWCOUNT @RowCount
IF(@EmailType = -1
    BEGIN
    SELECT
        em.ID as 'EmailID',
        em.Name as 'EmailName',
        ej.CreateDate as 'EmailDate',
        em.Type as 'EmailType',
        em.EmailTemplateID as 'EmailTemplateID',
        es.Sent as 'Sent',
        es.Opened as 'Opened',
        es.Bounced as 'Bounced',
        es.Pagehits as 'PageHits'
    FROM
        dbo.[Email_Stats] es
        LEFT OUTER join dbo.EmailJob ej on ej.EmailID = es.ID
        LEFT OUTER JOIN dbo.Email em ON em.ID = es.ID

    WHERE
        ej.CreateDate between @BeginDate and @EndDate
        and (ej.ConditionalParentJobID IS NULL)
        and (em.ParentEmailID IS NULL)
    ORDER BY
        es.id

    END
ELSE 
    BEGIN
    SELECT
        em.ID as 'EmailID',
        em.Name as 'EmailName',
        ej.CreateDate as 'EmailDate',
        em.Type as 'EmailType',
        em.EmailTemplateID as 'EmailTemplateID',
        es.Sent as 'Sent',
        es.Opened as 'Opened',
        es.Bounced as 'Bounced',
        es.Pagehits as 'PageHits'
    FROM
        dbo.[Email_Stats] es
        LEFT OUTER join dbo.EmailJob ej on ej.EmailID = es.ID
        LEFT OUTER JOIN dbo.Email em ON em.ID = es.ID

    WHERE
        ej.CreateDate between @BeginDate and @EndDate
        AND (ej.ConditionalParentJobID IS NULL)
        AND (
                (@EmailType <> 7 and em.Type = @EmailType)
                OR 
                (@EmailType = 7 and em.Type in (7,8))
            )

    ORDER BY
        es.id

    END