I need help figuring out how to write a query against the employee database's employees table that will generate a list of all employees (EMPY_ID) and their retirement dates (RETIRE_DT) then take those results and run a second query against the payroll database's paychecks table looking for all payments (PAY_DT) made to the employee (EMPY_ID) after they retire (RETIRE_DT). I have this so far but I think I am heading down the wrong path. Still learning. Any help is appreciated.
WITH R as (select p.* from [paydatabase].[dbo].[PAY_DT] p inner join [employeedb].[dbo].[employees] e on p.EMPY_ID = e.EMPY_ID where e.RETIRE_DT <= '2020-01-01') SELECT * FROM R WHERE PAY_DT >= '2020-01-01'
https://stackoverflow.com/questions/66620715/query-to-compare-two-databases-and-find-only-those-paid-after-retire-date March 14, 2021 at 11:07AM
没有评论:
发表评论