"First of all, you run a script to find Contractor and Expense tables across all databases on you production server"
sorry if I am wrong, but why are you searching all databases and if you dont know the tables then what are you searching 🙂
also I think its a lot of code for something like,
select contractor name, max of expense and date from contractor
inner join expense on expense.contract_id = contrator.id"