Every time I use this syntax, I get the idea that there is probably a better way. All I want to do is update two columns in a table from another table. Am I doing this the best way? SQL-2000 is preferable, but I'd like to see other solutions too.
Also, note that the WHERE clause includes a limit on the employeeIDs. Is that worthwhile since there is an INNER JOIN on that table anyway?
asked Aug 23 '10 at 02:30 PM in Default
Your query looks fine. The where clause including the limit on the EmployeeID is definitely worthwhile, bacause there might be some records in the #ActEmpl which are not present in #EmpList, so those will not be updated and it looks like this is what you want. If I were to write the same update query, I would probably opt to restate my IN part as a join and also move the sub-select out like this:
There is no guarantee that this will generate a different execution plan though. You can Ctrl + L both queries to find out.Oleg
answered Aug 23 '10 at 04:53 PM