bberkovich of 1800 Radiator
4/11/2016 - 4:33 PM

DW Out By Whse/Category/Calendar Week

DW Out By Whse/Category/Calendar Week

-- DW Out - By Warehouse, Category, Calendar Week
				
SELECT LEFT(d.Cal_week,4) [Year]
	  ,RIGHT(d.cal_week,2) [week]						
       ,TransferDetailLineFromWhse WarehouseID						
       ,isnull(cg.GroupName, 'Other')  CategoryGroup						
       --,SUM(transferdetaillineqty)*-1  AS Qty 						
       ,SUM(transferdetaillinecost*transferdetaillineqty)*-1 AS Purchase						
       ,CAST('DWout' as VARCHAR) as POorigHL  												
FROM   gxwizmo_24..transferdetail a 						
       INNER JOIN gxwizmo_24..transfer b 						
         ON a.transferid = b.transferid						
       JOIN misc_10.dbo.LU_DATE D						
		 ON  cast(left(b.TransferIssuedDate,11) as smalldatetime) = d.cal_DATE				
	   LEFT JOIN product_10..lu_item it					
	     ON a.StockItem = it.item					
	   LEFT JOIN product_10..CategoryGroup cg					
		 ON it.category = cg.Category				
WHERE  transferdetaillineadjusttype IN ( 'Y' ) 						
       AND Dateadd(DAY, Datediff(DAY, 0, transferissueddate), 0) > Dateadd(MONTH, -15, Getdate())		
       AND TransferDetailLineFromWhse = 126				
GROUP  BY d.cal_week						
          ,TransferDetailLineFromWhse						
          ,cg.GroupName