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)


    Hi,

    I have the below table

    CREATE TABLE [dbo].[BookOrderTest](

    [TitleID] [int] NULL,

    [Title] [nvarchar](100) NULL,

    [Quantity] [int] NULL

    ) ON [PRIMARY]

    insert into bookordertest values (1,'The Catcher in the Rye',3)

    insert into bookordertest values (1,'The Catcher in the Rye',3)

    insert into bookordertest values (3,'The Great Gatsby',0)

    insert into bookordertest values (4,'Gone with the Wind',4)

    insert into bookordertest values (5,'Jane Eyre',5)

    insert into bookordertest values (7,'Age of Innocence',8)

    Select titleid, COUNT(*) cnt

    FROM BookOrderTest

    Group By titleid

    having COUNT(*)>1

    I want to send a email to Joe.Bloggs@google.com if there are duplicates returning and to advise which titleid they are. If there are no duplicates then no email to be sent.

    Any ideas?

    Do you have database mail set up on your server and have you ever used sp_Send_DBMail before?

    --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)