|
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?
(comments are locked)
|
|
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 Thank you Oleg. I think that I like your query better since it puts the case statements closer to the columns to be updated. I'll have to try that. As for the where statement, I should have mentioned that both the #Emplist and #ActEmpl tables always have the same records (i.e., the same employee IDs listed). But in that case, it sounds like I can skip the where statement for employee IDs.
Aug 24 '10 at 06:54 AM
Mark
+1 from me, 'cos Oleg's version is so much easier to read. :-)
Aug 24 '10 at 07:46 AM
ThomasRushton ♦
Thanks again for the answer. I gave you credit for answering the question, printed our your SQL statement branded with the "Syntax of Oleg," and tacked it upon my wall for future use.
Aug 24 '10 at 02:27 PM
Mark
@Mark Thank you. I would still try Ctrl + L both queries because it is highly probable that they are identical to the SQL Server :)
Aug 24 '10 at 02:39 PM
Oleg
(comments are locked)
|

