Select '汇总:' as 'ProductCode',
'汇总:' as 'SkuCode',
Sum(Pur.PurchaseQuantity) as PurchaseQuantity,
Sum(Iv.InvQuantity) as InvQuantity,
Sum(Sale.SaleQuantity) as SaleQuantity,
Sum(Sio.StockQuantity) as StockQuantity,
Sum(STPS.SkuNearWeekDaySale) as SkuNearWeekDaySale,
Sum(STPS.SkuNearTwoWeekDaySale) as SkuNearTwoWeekDaySale,
Sum(STPS.SkuNearMonthDaySale) as SkuNearMonthDaySale,
Sum(PurTotal.PurchaseQuantity) as TotalPurchaseQuantity,
Cast(
Round(
Case When ISNULL(Sum(Pur.PurchaseQuantity), 0) = 0 THen 0
Else
Case When ISNULL(Sum(Sale.SaleQuantity), 0) = 0 Then 0
When Sum(Sale.SaleQuantity) / Sum(Pur.PurchaseQuantity) > 999 Then 999
ELSE Sum(Sale.SaleQuantity) / Sum(Pur.PurchaseQuantity)
End
END, 2) as Decimal(15, 2)) as PurchaseSaleDays,
Cast(
ROUND(
Case When ISNULL(Sum(Iv.InvQuantity), 0) = 0 THen 0
Else
Case When ISNULL(Sum(Sale.SaleQuantity), 0) = 0 Then 9999
When Sum(Iv.InvQuantity) / Sum(Sale.SaleQuantity) > 9999 Then 9999
ELSE Sum(Iv.InvQuantity) / Sum(Sale.SaleQuantity)
End
END, 2) as Decimal(15, 2)) as StockSaleDays,
Cast(
Round(
Case when isnull(Sum(PurTotal.PurchaseQuantity), 0) = 0 Then 0
Else Sum(Iv.InvQuantity) / Sum(PurTotal.PurchaseQuantity)
End
,2) as Decimal(15, 2)) as StockRate
From V_Product sku(nolock)
SELECT SKUID, SUM(NearWeekDaySale) AS SkuNearWeekDaySale,
SUM(NearTwoWeekDaySale) AS SkuNearTwoWeekDaySale, SUM(NearMonthDaySale) AS SkuNearMonthDaySale
FROM Fact_Summary_ProductDaySales (nolock)
1 = 1
and StoreId in ({StoreId})
Select SkuId, Sum(Quantity) as InvQuantity
From dbo.Fact_Orig_InventoryVirtual (nolock)
1 = 1
and WarehouseId in ({WarehouseId})
Select SkuId, Sum(ProductQuantity) as SaleQuantity
From Fact_Summary_Sales (nolock)
1 = 1
={CreateDateBegin}]]>
and StoreId in ({StoreId})
Select SkuId, Sum(InStockQuantity) as PurchaseQuantity
From Fact_Summary_Purchase (nolock)
1 = 1
={CreateDateBegin}]]>
and WarehouseId in ({WarehouseId})
Select SkuId, Sum(InStockQuantity) as PurchaseQuantity
From Fact_Summary_Purchase (nolock)
Select SkuId, Sum(StockQuantity) as StockQuantity
From Fact_Summary_StockInOut (nolock)
1 = 1
={CreateDateBegin}]]>
and WarehouseId in ({WarehouseId})
1=1
and ProductCode in ({ProductCode})
and SkuCode in ({SkuCode})
and Brand ={Brand}