Receiving duplicate key insert error with DISTINCT clause

  • I'm fairly confident.

    @AbsTab is created as a table variable just above the INSERT.

    'absence' is a hard table, if we were not hitting the proper table here due to ownership we would be seeing a lot more problems then duplicate rows.

    @CloseAbs is a table variable created above this query and has a PK on abs_id,org_id...but we reference this table via a UNCORRELATED SUBQUERRY with a 'NOT IN'.

    Just a thought...the 'NOT IN' creates a 'Left Anti Semi Join' in the query plan. If I have duplicate abs_id's in this table could this cause the problem? Since this is a 'NOT IN', I would not expect it to create duplicates.

  • If I have duplicate abs_id's in this table could this cause the problem?

    I don't think so. Can you post the full code?

    bc

    [font="Arial Narrow"]bc[/font]

  • I have uploaded my sample code.

    disclaimer...i take no credit for this code, I simply have the joy of debugging it 😀

    This is a snippet of the original procedure, but I can duplicate the issue with this sample.

    Note: this works most of the time without problem, and only receives errors during peak load.

  • i'm sorry, i can't see anything that would allow dupes into the query and cause the PK violation. bc

    [font="Arial Narrow"]bc[/font]

Viewing 4 posts - 16 through 18 (of 18 total)

You must be logged in to reply to this topic. Login to reply