• What I was trying to achieve was to work out why the insert created the exception below every now and again and the initial analysis pointed to the DATEADD format but ended up being more complicated.

    System.Data.SqlClient.SqlException (0x80131904): Violation of UNIQUE KEY constraint. Cannot insert duplicate key in object.

    The end result was as follows:

    1) Both of the DATEADD method formats produce the exact same result, so you can use either, but the 0 as date argument "feels" better.

    2) The WHERE NOT EXIST does not guarantee (no atomic action) that the condition DOES NOT EXIST as the thread can be interrupted in between the select and the insert, which creates the exception.

    3) Always double and triple check the calling code to make sure that it's not calling the SQL without wrapping the code in an exception and trying again WHEN it fails if needs be. In this case, I just needed to ignore the exception.

    One thing I must say, it was a very interesting learning exercise.