I have written many sql queries over the course of the last several years but I've got one that the answer seems right in front of me but I just can't see it. So any input on the following problem would be greatly appreciated.I have two tables Managers and SalesManagerID Month Year Region 1 3 2004 East 2 4 2004 East 1 6 2004 EastSales Month Year Region ManagerID3,500 3 2004 East 1,100 4 2004 East4,650 5 2004 East5,989 6 2004 East
The task is to update the ManagerID value in the sales table with the correct value from the Managers table based on region, month and year. The managers table contains a record for each change in manager assignments which means you can't do a simple update based on joining Region, Month and Year because there won't be a record in the managers table for every region and year.The only solution I came up with is using loops and cursors which does work but these are rather large pools of data (30+ million rows) so I believe cursors and loops aren't a viable alternative.FYI! This is an old legacy system so changing the schema or things such as that aren't an optionHere's hoping some generous person out there can give me a couple of hints