Advertisement
KyOOOO

Untitled

Sep 4th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. SET QUOTED_IDENTIFIER ON
  2. SET ANSI_NULLS ON
  3. GO
  4.  
  5.  
  6. CREATE VIEW [dbo].[FACT_M3byShif]
  7. AS
  8. SELECT SUM(ISNULL(I.Uf_ZVN_M3PerM, 0) * ISNULL(M.qty, 0) * ISNULL(dbo.ZVN_GetPileLength(M.item), 0)) M3,
  9. a.CaSanXuat,
  10. a.XuongSanXuat,
  11. a.NgaySanXuat,
  12. a.site_ref
  13. FROM ERP.SyteLine_Apps.dbo.matltran_mst M WITH (NOLOCK)
  14. JOIN ERP.SyteLine_Apps.dbo.item_mst I WITH (NOLOCK)
  15. ON M.site_ref = I.site_ref
  16. AND M.item = I.item
  17. LEFT JOIN
  18. (
  19. SELECT -- j.job Lenh,
  20.  
  21. j.item,
  22. CAST(jt.trans_date AS DATE) NgaySanXuat,
  23. jt.Uf_ZVN_Machine XuongSanXuat,
  24. jt.shift CaSanXuat,
  25. SUM(jt.qty_complete + jt.qty_scrapped) SLSanXuatERP,
  26. j.site_ref
  27. FROM ERP.SyteLine_Apps.dbo.jobtran_mst jt
  28. JOIN ERP.SyteLine_Apps.dbo.job_mst j
  29. ON j.job = jt.job
  30. AND j.suffix = jt.suffix
  31. AND j.site_ref = jt.site_ref
  32. WHERE jt.posted = 1
  33. GROUP BY j.item,
  34. CAST(jt.trans_date AS DATE),
  35. jt.Uf_ZVN_Machine,
  36. jt.shift,
  37. j.site_ref
  38. ) a
  39. ON a.site_ref = M.site_ref
  40. AND a.item = M.item
  41. WHERE YEAR(a.NgaySanXuat) >= 2019
  42. AND a.CaSanXuat IS NOT NULL
  43. AND a.XuongSanXuat IS NOT NULL
  44. GROUP BY a.CaSanXuat,
  45. a.XuongSanXuat,
  46. a.NgaySanXuat,
  47. a.site_ref;
  48. GO
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement