select sum(OrderLines.quantity) as lastOrderQuantity, avg(OrderLines.price) as lastOrderPrice from #client.erpDatabase#.dbo.OrderLines WITH (NOLOCK) inner join #client.erpDatabase#.dbo.OrderHeaders WITH (NOLOCK) on OrderHeaders.orderheaderid = OrderLines.orderheaderid and OrderHeaders.#_dateColumn# = and OrderHeaders.DistributorID = and OrderHeaders.ManufacturerID = where OrderLines.ItemID = and year(OrderHeaders.#_dateColumn#) >= year( getDate() ) - 5 select cdr.cdr_recordid, cdr.cdr_dstname, cdr.cdr_dstcode, fsp.firstname as cmfirst, fsp.lastname as cmlast, cs.customersku as fslCustomerSku, pcdr.cdr_recordid as parentDistributorId from tbl_CDR_Distributors cdr with (nolock) left outer join tbl_fspro_members fsp with (nolock) on fsp.fspro_userid = cdr.mfr_bsr_id left outer join tbl_prd_customerskus cs with (nolock) on cs.ownerid = cdr.ownerid and cs.fsl_tablecode = cdr.fsl_tablecode and cs.mfrid = and cs.skuid = and customertype in ('dst','pdst') and customerid = cdr.cdr_recordid left outer join tbl_DST_Distributors dst with (nolock) on dst.dstid = cdr.FSL_dstid left outer join tbl_DST_Distributors pdst with (nolock) on pdst.dstid = dst.dstparentco left outer join tbl_CDR_Distributors pcdr with (nolock) on pcdr.FSL_dstid = pdst.dstid and pcdr.ownerid = and pcdr.fsl_tablecode = where cdr.OwnerID = and cdr.fsl_tablecode = and cdr.cdr_dstcode IN ()
select cdr_recordid, manufacturername, itemcode, description, lastorderdate, lastorderquantity, cdr_dstname as distributorname, cdr_dstcode as distributorcode, cmfirst, cmlast, DistributorItemCode, lastorderprice, PriceByUMCode, fslCustomerSku, parentDistributorId from qmd_stockedItems, qcf_fslDistributors where qmd_stockedItems.distributorcode = qcf_fslDistributors.cdr_dstcode and qmd_stockedItems.fseInclude = 'Y' union select cast(0 as integer) as cdr_recordid, manufacturername, itemcode, description, lastorderdate, lastorderquantity, distributorname, distributorcode, '' as cmfirst, '' as cmlast, DistributorItemCode, lastorderprice, PriceByUMCode, '' as fslCustomerSku, 0 as parentDistributorId from qmd_stockedItems where distributorcode not in () and qmd_stockedItems.fseInclude = 'Y' order by distributorname

NOTE: Distribution information is based on order history and may not reflect true stocking status.

    select customersku from tbl_prd_customerskus with (nolock) where ownerid = and fsl_tablecode = and customertype = 'pdst' and customerid = and skuid =
  • #replace(DistributorName,"/"," / ","all")#

    #_dateFieldLabel#: #dateformat(lastorderdate,"mm/dd/yyyy")# #_daysAgo# days ago

    Code: #_customerSku#

    Qty: #numberformat(lastorderquantity,"9,999")#, Price: $#numberformat(lastorderprice,"9,999.99")#/#PriceByUMCode#