• well, if a given id exists more than once in your tbl_directdebits, it will insert multiple rows.

    ...from tbl_directdebits where id= @id

    does this query return any rows?

    SELECT id, count(id)

    FROM tbl_directdebits

    GROUP BY id

    HAVING count(id) > 1

    based on that command delete from tbl_directdebits where duplicateof=@id id say that whatever logic you have in palce that updates/populates the column duplicateof is broken or failing, if that is how you test for whether an id exists or not.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!