• Sean Lange (9/6/2013)


    John.Hagen (9/6/2013)


    Hi Everyone

    I have a merge statement which ends with the following

    WHEN NOT MATCHED BY SOURCE THEN

    DELETE;

    Now I need to record the deleted records in a table and I am having no luck getting the output to work. The records I need to record look like the following.

    OID (int)

    Version (int)

    QK varchar(32)

    GD varchar(32)

    Geometry (Geometry)

    and I would like to add a date column to record when the delete took place.

    What do you mean that you are not having any luck getting output to work? I don't see OUTPUT in your query here at all. You can reference the deleted virtual table in a MERGE statement just like a trigger.

    ???

    Did you mean to simply just quote this or did you forget to add something?

    Something like this help?

    WHEN NOT MATCHED BY SOURCE THEN

    DELETE

    OUTPUT

    deleted.OID,

    deleted.Version,

    deleted.QK,

    deleted.GD,

    deleted.Geometry,

    GETDATE()

    INTO SomeTable

    --EDIT--

    Forgot to include deleted. 🙂

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/