• Bhuvnesh (1/1/2013)


    opc.three (1/1/2013)


    With the query written this way I can highlight the SELECT statement in the USING clause to see what would be deleted without changing the query or carrying additional debug-comments in the code:

    thanks for this awesome approach , can you please help with the SELECT (you mentioned in quote) query for below query ?

    BEGIN TRAN;

    MERGE dbo.BC_ShiftSummaryInfo AS target

    USING

    (

    SELECT A.SS_ID

    FROM dbo.BC_ShiftSummaryInfo A

    JOIN dbo.BC_ShiftSummary B ON A.SS_ID = B.SS_ID

    WHERE B.ShiftStartDate BETWEEN '2012-12-14 06:00:00.000'

    AND '2012-12-14 22:00:00.000'

    ) AS source (SS_ID)

    ON source.SS_ID = target.SS_ID

    WHEN MATCHED

    THEN DELETE;

    ROLLBACK;

    What did you want to know? If you were thinking this MERGE would de-duplicate the range, it won't. I was just showing an alternate to using DELETE-JOIN that might be a little more expressive.

    Only deleting duplicatesedit, added within the range of ShiftStartDate specified requires additional information. We started to go down this road over here but maybe it is not required.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato