Advertisement
imk0tter

Untitled

Feb 18th, 2012
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 0.79 KB | None | 0 0
  1.         SELECT
  2.             D.PartID,
  3.             D.PartType,
  4.             D.PartName,
  5.             E.PartTypeName,
  6.             A.EntryDate,
  7.             COALESCE(B.UsedPartCount,0) AS UsedPartCount
  8.         FROM
  9.         DateTable AS A
  10.         LEFT JOIN
  11.         (
  12.             SELECT
  13.                 COALESCE(COUNT(1),0) AS UsedPartCount,
  14.                 COALESCE(A.PartID,0) AS PartID,
  15.                 DATEADD(dd,0,DATEDIFF(dd,0,B.RepairDate)) AS RepairDate
  16.             FROM
  17.                 JobEntryPartTable AS A
  18.                 INNER JOIN
  19.                 JobEntryTable AS B
  20.                 ON A.JobEntryID = B.JobEntryID
  21.                 INNER JOIN
  22.                 JobPartTypeTable AS C
  23.                 ON A.PartType = C.PartType
  24.             WHERE
  25.                 PartID > 1 AND C.Remove = 1
  26.             GROUP BY
  27.                 PartID, RepairDate
  28.         ) AS B
  29.         ON A.EntryDate = B.RepairDate
  30.         INNER JOIN
  31.         PartTable AS D
  32.         ON B.PartID = D.PartID
  33.         INNER JOIN
  34.         PartTypeTable AS E
  35.         ON D.PartType = E.PartType
  36.         WHERE
  37.             B.UsedPartCount > 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement