Home Forums SQL Server 2008 T-SQL (SS2K8) Check for duplicate and send email of duplicates to End User RE: Check for duplicate and send email of duplicates to End User

  • SQL_Kills (10/27/2016)


    I think I have seen it somewhere but I'm not sure how to use the PRINT to displace the sublimate values on the BODY of the email?

    Yabingooglehoo helps here a lot. See the following URL.

    https://msdn.microsoft.com/en-us/library/ms190307.aspx

    Example "B" is similar to solving your problem as I did in the code below. You can make things much more pretty by taking a look at example "C".

    Here's the simple code:

    SELECT TitleID, COUNT(*) cnt

    INTO ##Results

    FROM dbo.BookOrderTest

    GROUP BY TitleID

    HAVING COUNT(*)>1

    ;

    IF @@ROWCOUNT > 0

    EXEC msdb.dbo.sp_send_dbmail

    @recipients = 'put email address(es) here',

    @query = 'SET NOCOUNT ON; SELECT * FROM ##Results' ,

    @subject = 'Duplicate Book Orders',

    @body = 'Put any amplifying information you want to send here.'

    ;

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)