Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT
- D.PartID,
- D.PartType,
- D.PartName,
- E.PartTypeName,
- A.EntryDate,
- COALESCE(B.UsedPartCount,0) AS UsedPartCount
- FROM
- DateTable AS A
- LEFT JOIN
- (
- SELECT
- COALESCE(COUNT(1),0) AS UsedPartCount,
- COALESCE(A.PartID,0) AS PartID,
- DATEADD(dd,0,DATEDIFF(dd,0,B.RepairDate)) AS RepairDate
- FROM
- JobEntryPartTable AS A
- INNER JOIN
- JobEntryTable AS B
- ON A.JobEntryID = B.JobEntryID
- INNER JOIN
- JobPartTypeTable AS C
- ON A.PartType = C.PartType
- WHERE
- PartID > 1 AND C.Remove = 1
- GROUP BY
- PartID, RepairDate
- ) AS B
- ON A.EntryDate = B.RepairDate
- INNER JOIN
- PartTable AS D
- ON B.PartID = D.PartID
- INNER JOIN
- PartTypeTable AS E
- ON D.PartType = E.PartType
- WHERE
- B.UsedPartCount > 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement