Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1.  
  2. SELECT pd.PromotionID, pd.Descr,
  3. pd.SchemeID,pd.EffectiveDate, pd.EndDate,
  4. cd.DistributorID,
  5. dl.DistributorName,
  6. cde.InventoryID AS FocID,
  7. ii.Descr AS FocName,
  8. COUNT( cde.InventoryID) AS Quanity,
  9.  
  10. CASE WHEN cde.Rate IS NOT NULL
  11. THEN cde.ChangingInventoryID
  12. WHEN cde.Rate IS NULL
  13. THEN cde.InventoryID
  14. END
  15. SKU,
  16. CASE WHEN cde.ChangingInventoryID IS NOT NULL
  17. THEN (SELECT i1.Descr FROM MRCDMS..InventoryItem i1 WHERE i1.InventoryID = cde.ChangingInventoryID)
  18. WHEN cde.ChangingInventoryID IS NULL
  19. THEN ii.Descr
  20. END
  21. SkuName,
  22. ---Rate
  23. CASE WHEN cde.Rate IS NOT NULL
  24. THEN cde.Rate
  25. WHEN cde.Rate IS NULL
  26. THEN 1
  27. END
  28. Rate,
  29. CASE WHEN cde.Rate IS NOT NULL
  30. THEN (cde.Rate *(COUNT( cde.InventoryID)))
  31. WHEN cde.Rate IS NULL
  32. THEN (1 *(COUNT( cde.InventoryID)))
  33. END
  34. SkuQuantity
  35.  
  36. FROM MRCDMS..DMSPRODiscount pd ----Define program Discount
  37. INNER JOIN MRCDMS..DMSClaimDistributors --Get Distributor
  38. cd ON cd.CompanyID = pd.CompanyID
  39. AND pd.PromotionID = cd.ProgramID INNER JOIN
  40. MRCDMS..DMSClaimDefine cld -- Claim Define Type P : Promotion , L:Loyalty, V:Visibility
  41. ON cld.CompanyID = cd.CompanyID AND cld.RefNbr = cd.RefNbr
  42. INNER JOIN DMSBLDistributorLocation dl -- Get distributor location detail
  43. ON dl.CompanyID = cd.CompanyID AND cd.DistributorID = dl.DistributorID
  44. INNER JOIN (
  45. --Get top DMSClaimDetails by RefNbr, LineNBR following ProgramID and Inventory
  46. SELECT * FROM ( SELECT RANK() OVER (PARTITION BY cds.ProgramID,
  47. cds.InventoryID ORDER BY cds.RefNbr DESC, cds.LineNbr DESC) AS RankRef,
  48. cds.CompanyID, cds.RefNbr,cds.ProgramID,
  49. cds.InventoryID, cds.Rate, cds.LineNbr, cds.ChangingInventoryID FROM MRCDMS..DMSClaimDetails cds)
  50. temp WHERE temp.RankRef = 1) cde --Detail program detail
  51. ON cde.CompanyID = cd.CompanyID
  52. AND cde.ProgramID = pd.PromotionID
  53. INNER JOIN MRCDMS..InventoryItem ii -- Inventory Item
  54. ON ii.CompanyID = cde.CompanyID
  55. AND cde.InventoryID = ii.InventoryID
  56. WHERE cd.Status = 'A' --Acknown
  57. AND cld.Type = 'P' --Type promotion
  58. GROUP BY pd.PromotionID, pd.Descr,
  59. pd.SchemeID,pd.EffectiveDate, pd.EndDate,
  60. cd.DistributorID,
  61. dl.DistributorName,
  62. cde.InventoryID,
  63. ii.Descr,
  64. cde.Rate,
  65. cde.ChangingInventoryID
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement