• tfifield (1/14/2011)


    Damn! I thought I'd never say this but score 1 for Joe.

    Actually the FROM syntax is very useful as a previous poster mentioned in that the UPDATE can be commented out and replaced with a SELECT to see the count of rows. I can quickly eyeball what's about to be updated. Afte that I usually put a GROUP BY HAVING COUNT(*) > 1 in the select just to make sure there isn't something that I don't know about in the data. Not a perfect solution since it could pop up periodically.

    Todd Fifield

    You can still get more than an idea of how the update will end up looking.

    begin transaction;

    merge ...

    output inserted.*;

    commit;

    Don't run the commit till you're happy with the data in the output grid.

    If you don't want to hold a transaction open, use rollback on the test run, then commit when you're sure it's giving you what you want.

    The Output clause has been possible since SQL 2005, and is better than eyeballing a Select version of an Update syntax, since you don't have to change any of the command in order to run it.

    Edit: For clarity.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon