Efficiently perform multiple similar updates I'm trying to extend some existing SQL (SQL Server) that builds a table of all items to act on using a number of queries. Some of these are very similar and costly, and I was hoping to get some advice on how to either combine them or rework this section to avoid doing the hard query multiple times. My SQL experience is a bit shallow, so maybe there is an obvious solution to this.

--Move Messages if moveMessages=1
UPDATE t1
SET t1.foo = temp.newFoo,
    t1.bar = temp.newBar
FROM Table1 t1
INNER JOIN @TempTable TEMP ON TEMP.baz = t1.bar
                          AND TEMP.moveMessages = 1
INNER JOIN Table2 t2 ON t2.type = 'M'
                    AND t1.thingId = t2.thingId

--Move Documents if moveDocuments=1
UPDATE t1
SET t1.foo = TEMP.newFoo,
    t1.bar = TEMP.newBar
FROM Table1 t1
INNER JOIN @TempTable TEMP ON TEMP.baz = t1.bar
                          AND TEMP.moveDocuments = 1
INNER JOIN Table2 t2 ON t2.type = 'D'
                    AND t1.thingId = t2.thingId 


There are more repetitions of the above, but the only difference between each one is which column in TEMP is checked, and which letter is referenced for t2.type. So for example, for any rows in TEMP that have moveMessages=1, move all the 'M' types. For each row in TEMP that has moveDocuments=1, move all the 'D' types, and so on.

Is there a way to do all of this in one statement? Is this a situation when I should use another temporary table?
One of the nice things about INNER JOIN syntax is that it actually allows you to separate filter criteria from join criteria. The two statements in your question could be collapsed into a single query as follows:

UPDATE t1
SET t1.foo = temp.newFoo,
    t1.bar = temp.newBar
FROM dbo.Table1 t1 -- please always use schema qualifiers
INNER JOIN @TempTable TEMP 
  ON TEMP.baz = t1.bar
INNER JOIN dbo.Table2 t2 
  ON t1.thingId = t2.thingId
WHERE (TEMP.moveMessages  = 1 AND t2.type = 'M')
   OR (TEMP.moveDocuments = 1 AND t2.type = 'D');