Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. /*
  2. REPORT TO GENEATE OLD INVENTORY BY QUARTER SUMMARY
  3. This is working accurately as of 4/8/19.
  4.  
  5. TODO:
  6. SET TO RUN WITH INPUT VARIABLES RATHER THAN STATIC CODED CLASSES AND DATES
  7. CHECK THAT THE INNER SELECT MATH IS ACCURATE - SOME OF THE NUMBERS LOOKED SLIGHTLY OFF.
  8. THERE IS A VIEW FUNCITON THAT THIS REPORT CHECKS IN THE ANALYSIS SIDE OF THINGS AND IT produces different results
  9. */
  10.  
  11. use Celerant
  12. set nocount on
  13. set ansi_warnings off
  14. select
  15.  
  16. TB_TAXONOMY.DEPT,
  17. tb_taxonomy.typ,
  18. tb_taxonomy.SUBTYP_1,
  19. tb_taxonomy.SUBTYP_2,
  20. tb_taxonomy.SUBTYP_3,
  21. sum(sku_group.qoh *sku_group.PRICE) as total_oh,
  22. sum(case when (datepart(Q, sku_group.LAST_RCVD) = '1' and datepart(YEAR, sku_group.LAST_RCVD) = '2019')then (sku_group.QOH*sku_group.PRICE) else 0 end) as MO_0to3,
  23. sum(case when (datepart(Q, sku_group.LAST_RCVD) = '4' and datepart(YEAR, sku_group.LAST_RCVD) = '2018')then (sku_group.QOH*sku_group.PRICE) else 0 end) as MO_3to6,
  24. sum(case when (datepart(Q, sku_group.LAST_RCVD) = '3' and datepart(YEAR, sku_group.LAST_RCVD) = '2018')then (sku_group.QOH*sku_group.PRICE) else 0 end) as MO_6to9,
  25. sum(case when (datepart(Q, sku_group.LAST_RCVD) = '2' and datepart(YEAR, sku_group.LAST_RCVD) = '2018')then (sku_group.QOH*sku_group.PRICE) else 0 end) as MO_9to12,
  26. sum(case when (sku_group.LAST_RCVD <= '2018-03-31') then (sku_group.QOH*sku_group.PRICE) else 0 end) as MO_12
  27.  
  28.  
  29.  
  30. FROM
  31. (
  32. select
  33. tb_skus.sku_id as sku_id,
  34. sum(TB_SKU_BUCKETS.QOH) as qoh,
  35. avg(tb_sku_buckets.PRICE) as price,
  36. max(TB_SKU_BUCKETS.LAST_RCVD) as last_rcvd
  37. from TB_SKUS
  38. inner join
  39. TB_SKU_BUCKETS on tb_skus.SKU_ID = TB_SKU_BUCKETS.SKU_ID
  40. inner join TB_STYLES on TB_SKUS.STYLE_ID = TB_STYLES.STYLE_ID
  41. group by tb_skus.SKU_ID
  42.  
  43. )sku_group
  44. left join TB_SKUS on TB_SKUS.sku_id = sku_group.sku_id
  45. left join TB_STYLES on TB_STYLES.STYLE_Id = TB_SKUS.STYLE_ID
  46. left join TB_TAXONOMY on TB_STYLES.TAXONOMY_ID = TB_TAXONOMY.TAXONOMY_ID
  47.  
  48.  
  49.  
  50. where
  51. TB_TAXONOMY.DEPT = 'inline'
  52. and
  53. (TB_TAXONOMY.TYP = 'Aftercare / repair'
  54. or
  55. TB_TAXONOMY.TYP = 'backpking / campng'
  56. or
  57. TB_TAXONOMY.TYP = 'electronics'
  58. or
  59. TB_TAXONOMY.TYP = 'first aid / hygiene'
  60. or
  61. TB_TAXONOMY.TYP = 'food / nutrition'
  62. or
  63. TB_TAXONOMY.TYP = 'storage'
  64. )
  65.  
  66.  
  67.  
  68. GROUP BY
  69.  
  70. TB_TAXONOMY.DEPT,
  71. tb_taxonomy.typ,
  72. tb_taxonomy.SUBTYP_1,
  73. tb_taxonomy.SUBTYP_2,
  74. tb_taxonomy.SUBTYP_3
  75.  
  76. ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement