我试过了,老是出现:
Server: Msg 245, Level 16, State 1, Line 29
Syntax error converting the varchar value 'OR6246' to a column of data type int.
我找不到原因,你看看我的代码,我不清楚为什么会得不到想要的结果:
ALTER Procedure TrimPO_PaxarPrice @HeadID Varchar(9)
As
Declare @Sql Varchar(8000)
Set @Sql='Select PO,ColorEng,Remark'
Select @Sql=@sql+',['+dd+']=sum(case Size when '''+dd+''' then TTQty else 0 end)'
from (select distinct dd=Size from TrimPO_InputData where HeadID=@HeadID ) ss
set @sql=@sql+'into ##kk From TrimPO_InputData where HeadID='+''+@HeadID+''+' Group by PO,ColorEng,Remark '
exec(@sql)
Select distinct PO,SubString(ColorEng,1,Charindex(' ',ColorEng)-1) ColorCode,Remark from ##kk
Select distinct PO,SubString(ColorEng,1,Charindex(' ',ColorEng)-1) ColorCode,Remark into #dd from ##kk
Create Table #aa
(
id Int,
inf Varchar(50),
Code Varchar(10)
)
Declare @PO Varchar(15)
Declare @POx Varchar(15)
Declare @Color Varchar(10)
Declare @Reamrk Varchar(10)
Declare @PO2 Varchar(15)
Declare @Color2 Varchar(10)
Declare @Reamrk2 Varchar(10)
Declare @iCount Int
Declare PO_Cur Cursor For
Select distinct PO,SubString(ColorEng,1,Charindex(' ',ColorEng)-1) ColorCode,Remark from ##kk
Open PO_Cur
Fetch PO_Cur Into @PO,@Color,@Reamrk
While @@Fetch_Status=0
begin
Set @iCount=1
Declare t_cur cursor for
Select PO,ColorCode,Remark From #dd Where PO=@PO --and ColorCode=@Color
open t_cur
fetch t_cur into @PO2,@Color2,@Reamrk2
While @@Fetch_Status=0
begin
if (@iCount=1)
begin
Insert into #aa (id,inf,Code) values (@iCount,@PO,@Color)
end
else if (@iCount=2)
begin
Insert into #aa (id,inf,Code) values (@iCount,@Reamrk2,Isnull(@Color,''))
end
else if (@iCount>2)
begin
Insert into #aa (id,inf,Code) values (@iCount,'',Isnull(@Color,