• 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;

    -------Bhuvnesh----------
    I work only to learn Sql Server...though my company pays me for getting their stuff done;-)