Question : SQL -  Filter Dates from Two Different Tables

I have three tables that I am working with that I am trying to create a VIEW for running a report.  Basically, I am trying to determine the Qty from our ScrapTrasactions and JobOrders by any given date.  I am able to create the VIEW to show me the Qtys by PartNumber with no problem, but I am hitting a wall I add the date fields so that I can filter by a certain date, since the dates are from two different tables.  

Below is basically what I have :

      Table:  Inventory
      Fileds:     PartNumber
                     Description
                               Category
      

      Table: ScrapTransactions
      Fields:   TransactionDate
                   PartNumber
                   Qty


      Table: JobOrders
      Fields:   JobOrderNumber
                   JobOrderDate
                   PartNumber
                   Qty


Desired Result to be filtered by date:

Date (TransactionDate or JobOrderDate)
Inventory.PartNumber
Inventory.Description
SUM(ScrapTransaction.Qty)
SUM(JobOrders.Qty)

Answer : SQL -  Filter Dates from Two Different Tables

try this

Select
Inventory.PartNumber, Inventory.Description,
Sum(ScrapTrans_Qty) , Sum(JobOrder_Qty)
From
Inventory Left outer join
(Select PartNumber, TransactionDate as [Date], Sum(Qty) ScrapTrans_Qty, 0 JobOrder_Qty
from ScrapTransactions group by PartNumber, TransactionDate
Union All
Select PartNumber, JobOrderDate, 0 ScrapTrans_Qty, Sum(Qty) JobOrder_Qty
from JobOrders group by PartNumber, JobOrderDate) A
on Inventory.PartNumber = A.PartNumber
where A.[Date] between 'startDateValue' and 'endDateValue'
Group by Inventory.PartNumber, Inventory.Description
Random Solutions  
 
programming4us programming4us