SQL Server 2008 - Display record depending on status of data in another table
Posted on 2013-05-28
Trying to figure out how to write the SQL for the below scenario.
- Lets say we have two tables Invoice and Timesheet.
- The Invoice table is used to pay all Timesheets.
- A user can work on the timesheet until they submit it. Once it is submitted then it needs to be approved, rejected, or closed.
So, If the timesheet is new or open then I do not want the related invoice record to display. It can only display if all associated timesheets are either approved, rejected, or closed.
Sample Table structure
- Invoice.InvoiceID, Invoice.Status, Invoice.Amt, Invoice.PaidBy, Invoice.PaidOn
- Timesheet.TimesheetID, Timesheet.InvoiceID, Timesheet.Status, TimeSheet.Rate, Timesheet.HoursWorked, Timesheet.Travel, Timesheet.Food, Timesheet.Gas, Timesheet.Hotel