日期:2014-05-17 浏览次数:20415 次
ALTER Procedure [dbo].[ShipDateQtyPush_Plan]
@S Varchar(10),
@F Varchar(10),
@FnSam Varchar(15),
@FnQty Varchar(15),@Grade Float
As
Create Table #a
(
PO Varchar(20),
Season Varchar(10),
Style Varchar(20),
ShipDate Varchar(10),
Customer Varchar(10),
Color Varchar(50),
Qty Int,
CuttingQty Int,
Qty226 Int,
Sam Float,
ActQty Int,
DiffQty Int
)
Declare @str Varchar(8000)
Set @str=' Insert into #a
Select
PO,Season,Style,Convert(Varchar(10),ShipDate,120) ShipDate,Customer,Color,
Sum(Qty) Qty,Sum(CuttingQty) CuttingQty,Sum(Qty226) Qty226,'+@FnSam+' Sam,
Sum('+@FnQty+') ActQty,Sum(Qty-'+@FnQty+') DiffQty
from
ShipDateQtyPush
where
ShipDate>='''+@S+''' and ShipDate<='''+@F+'''
Group by
PO,Season,Style,ShipDate,Customer,Color,Sam331 '
Exec(@str)
--------------------------------------------------------------------
declare @sql varchar(8000)
set @sql='select PO,Season,Style,Customer,ShipDate,Color,Qty,CuttingQty,Qty226,Round(Sam,2) Sam,ActQty'
select @sql=@sql+',['+dd+'ろ计]=sum(case Convert(Varchar(10),ShipDate,120) when '''+dd+''' then DiffQty else 0 end)'
+',['+dd+'惠]=sum(case Convert(Varchar(10),ShipDate,120) when '''+dd+''' then Round((Qty-ActQty)*(Sam'+@Grade+')/60,2) else 0 end)'
from (select distinct dd=Convert(Varchar(10),ShipDate,120) from #a) ss
set @sql=@sql+' from #a group by PO,Season,Style,Customer,ShipDate,Color,Qty,CuttingQty,Qty226,Sam,ActQty'
exec(@sql)
Drop table #a
--需要转@Grade为文本才能添加在@sql中
declare @sql varchar(8000)
set @sql='select PO,Season,Style,Customer,ShipDate,Color,Qty,CuttingQty,Qty226,Round(Sam,2) Sam,ActQty'
select @sql=@sql+',['+dd+'ろ计]=sum(case Convert(Varchar(10),ShipDate,120) when '''+dd+''' then DiffQty else 0 end)'
+',['+dd+'惠]=sum(case Convert(Varchar(10),ShipDate,120) when '''+dd+''' then Round((Qty-ActQty)*(Sam'+convert(varchar,@Grade)+')/60,2) else 0 end)' ----这里
from (select distinct dd=Convert(Varchar(10),ShipDate,120) from #a) ss
set @sql=@sql+' from #a group by PO,Season,Style,Customer,ShipDate,Color,Qty,CuttingQty,Qty226,Sam,ActQty'