储存过程执行出现的问题
代码如下:
ALTER Procedure [dbo].[ShipDateQtyPush_Plan]
@SVarchar(10),
@FVarchar(10),
@FnSamVarchar(15),
@FnQtyVarchar(15),@GradeFloat
As
Create Table #a
(
POVarchar(20),
SeasonVarchar(10),
StyleVarchar(20),
ShipDateVarchar(10),
CustomerVarchar(10),
ColorVarchar(50),
QtyInt,
CuttingQtyInt,
Qty226Int,
SamFloat,
ActQtyInt,
DiffQtyInt
)
Declare @strVarchar(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'
exec(@sql)
Drop table #a
(Sam'''+CAST(@Grade AS VARCHAR)+''')