代码很长,自动换行后不易看。这是实际的例子。你凑合看吧。
dmInventory.qinvd.close;
dmInventory.qinvd.sql.text:=' CREATE TABLE #te ('+
'gperm2 smallint, grade char(2), w1 float null, b1 float null, w2 float null, b2 float null, '+
'w3 float null, b3 float null, w4 float null, b4 float null, w5 float null, b5 float null, '+
'w6 float null, b6 float null, w7 float null, b7 float null, w8 float null, b8 float null, '+
'w9 float null, b9 float null, w10 float null, b10 float null, wRoll float null, bRoll float null, '+
'inv float null, invb float null )'+
'declare @gperm2 smallint declare @grade char(2) declare @w1 float declare @b1 float '+
'declare @w2 float declare @b2 float declare @w3 float declare @b3 float declare @w4 float '+
'declare @b4 float declare @w5 float declare @b5 float declare @w6 float declare @b6 float '+
'declare @w7 float declare @b7 float declare @w8 float declare @b8 float declare @w9 float '+
'declare @b9 float declare @w10 float declare @b10 float declare @wRoll float declare @bRoll float '+
'declare @inv float declare @invb float '+
'declare c_InvStruc cursor for select distinct gperm2,grade from inventory i,vproductdata v,stores s '+
'where i.productno=v.productno and s.storeNo=i.storeNo and s.status=''n'' and s.compNo="0000" and (i.weight<>0 or i.wtemp<>0 or i.wbooked<>0 or wway<>0) and '+
'(productName="" ';
te:='';
tu:='';
for i:=0 to checklistbox1.Items.Count-1 do
begin
if checklistbox1.checked then
te:=te+' or productName='''+checklistbox1.items+'''';
end;
n:=0;
frmrepd.qrl1.caption:='';
frmrepd.qrl2.caption:='';
frmrepd.qrl3.caption:='';
frmrepd.qrl4.caption:='';
frmrepd.qrl5.caption:='';
frmrepd.qrl6.caption:='';
frmrepd.qrl7.caption:='';
frmrepd.qrl8.caption:='';
frmrepd.qrl9.caption:='';
frmrepd.qrl10.caption:='';
for i:=0 to checklistbox2.Items.Count-1 do
begin
if checklistbox2.checked then
begin
n:=n+1;
if n>10 then
begin
showmessage('规格值超过10个,报表无法打印!');
abort;
end
else
begin
case n of
1: begin
frmrepd.qrl1.caption:=checklistbox2.Items;
tu:=tu+' select @w1=convert(float,sum(i.weight+i.wtemp)/1000),@b1=convert(float,sum(wBooked)/1000) '+
' from vproductdata v,inventory i,stores s where i.productNo=v.productNo and s.storeNo=i.storeNo and s.status=''n'' and s.compNo="0000" and (i.weight<>0 or i.wtemp<>0 or i.wbooked<>0 or wway<>0) '+
' and gperm2=@gperm2 and grade=@grade and '+
' (productName="" '+te+') and sizespec="'+checklistbox2.Items+'" update #te set w1=@w1,b1=@b1 where gperm2=@gperm2 and grade=@grade ';{ }
end;
2: begin
frmrepd.qrl2.caption:=checklistbox2.Items;
tu:=tu+' select @w2=convert(float,sum(i.weight+i.wtemp)/1000),@b2=convert(float,sum(wBooked)/1000) '+
' from vproductdata v,inventory i,stores s where i.productNo=v.productNo and s.storeNo=i.storeNo and s.status=''n'' and s.compNo="0000" and (i.weight<>0 or i.wtemp<>0 or i.wbooked<>0 or wway<>0) '+
' and gperm2=@gperm2 and grade=@grade and '+
' (productName="" '+te+') and sizespec="'+checklistbox2.Items+'" update #te set w2=@w2,b2=@b2 where gperm2=@gperm2 and grade=@grade ';
end;
3: begin
frmrepd.qrl3.caption:=checklistbox2.Items;
tu:=tu+' select @w3=convert(float,sum(i.weight+i.wtemp)/1000),@b3=convert(float,sum(wBooked)/1000) '+
' from vproductdata v,inventory i,stores s where i.productNo=v.productNo and s.storeNo=i.storeNo and s.status=''n'' and s.compNo="0000" and (i.weight<>0 or i.wtemp<>0 or i.wbooked<>0 or wway<>0) '+
' and gperm2=@gperm2 and grade=@grade and '+
' (productName="" '+te+') and sizespec="'+checklistbox2.Items+'" update #te set w3=@w3,b3=@b3 where gperm2=@gperm2 and grade=@grade ';
end;
4: begin
frmrepd.qrl4.caption:=checklistbox2.Items;
tu:=tu+' select @w4=convert(float,sum(i.weight+i.wtemp)/1000),@b4=convert(float,sum(wBooked)/1000) '+
' from vproductdata v,inventory i,stores s where i.productNo=v.productNo and s.storeNo=i.storeNo and s.status=''n'' and s.compNo="0000" and (i.weight<>0 or i.wtemp<>0 or i.wbooked<>0 or wway<>0) '+
' and gperm2=@gperm2 and grade=@grade and '+
' (productName="" '+te+') and sizespec="'+checklistbox2.Items+'" update #te set w4=@w4,b4=@b4 where gperm2=@gperm2 and grade=@grade ';
end;
5: begin
frmrepd.qrl5.caption:=checklistbox2.Items;
tu:=tu+' select @w5=convert(float,sum(i.weight+i.wtemp)/1000),@b5=convert(float,sum(wBooked)/1000) '+
' from vproductdata v,inventory i,stores s where i.productNo=v.productNo and s.storeNo=i.storeNo and s.status=''n'' and s.compNo="0000" and (i.weight<>0 or i.wtemp<>0 or i.wbooked<>0 or wway<>0) '+
' and gperm2=@gperm2 and grade=@grade and '+
' (productName="" '+te+') and sizespec="'+checklistbox2.Items+'" update #te set w5=@w5,b5=@b5 where gperm2=@gperm2 and grade=@grade ';
end;
6: begin
frmrepd.qrl6.caption:=checklistbox2.Items;
tu:=tu+' select @w6=convert(float,sum(i.weight+i.wtemp)/1000),@b6=convert(float,sum(wBooked)/1000) '+
' from vproductdata v,inventory i,stores s where i.productNo=v.productNo and s.storeNo=i.storeNo and s.status=''n'' and s.compNo="0000" and (i.weight<>0 or i.wtemp<>0 or i.wbooked<>0 or wway<>0) '+
' and gperm2=@gperm2 and grade=@grade and '+
' (productName="" '+te+') and sizespec="'+checklistbox2.Items+'" update #te set w6=@w6,b6=@b6 where gperm2=@gperm2 and grade=@grade ';
end;
7: begin
frmrepd.qrl7.caption:=checklistbox2.Items;
tu:=tu+' select @w7=convert(float,sum(i.weight+i.wtemp)/1000),@b7=convert(float,sum(wBooked)/1000) '+
' from vproductdata v,inventory i,stores s where i.productNo=v.productNo and s.storeNo=i.storeNo and s.status=''n'' and s.compNo="0000" and (i.weight<>0 or i.wtemp<>0 or i.wbooked<>0 or wway<>0) '+
' and gperm2=@gperm2 and grade=@grade and '+
' (productName="" '+te+') and sizespec="'+checklistbox2.Items+'" update #te set w7=@w7,b7=@b7 where gperm2=@gperm2 and grade=@grade ';
end;
8: begin
frmrepd.qrl8.caption:=checklistbox2.Items;
tu:=tu+' select @w8=convert(float,sum(i.weight+i.wtemp)/1000),@b8=convert(float,sum(wBooked)/1000) '+
' from vproductdata v,inventory i,stores s where i.productNo=v.productNo and s.storeNo=i.storeNo and s.status=''n'' and s.compNo="0000" and (i.weight<>0 or i.wtemp<>0 or i.wbooked<>0 or wway<>0) '+
' and gperm2=@gperm2 and grade=@grade and '+
' (productName="" '+te+') and sizespec="'+checklistbox2.Items+'" update #te set w8=@w8,b8=@b8 where gperm2=@gperm2 and grade=@grade ';
end;
9: begin
frmrepd.qrl9.caption:=checklistbox2.Items;
tu:=tu+' select @w9=convert(float,sum(i.weight+i.wtemp)/1000),@b9=convert(float,sum(wBooked)/1000) '+
' from vproductdata v,inventory i,stores s where i.productNo=v.productNo and s.storeNo=i.storeNo and s.status=''n'' and s.compNo="0000" and (i.weight<>0 or i.wtemp<>0 or i.wbooked<>0 or wway<>0) '+
' and gperm2=@gperm2 and grade=@grade and '+
' (productName="" '+te+') and sizespec="'+checklistbox2.Items+'" update #te set w9=@w9,b9=@b9 where gperm2=@gperm2 and grade=@grade ';
end;
10: begin
frmrepd.qrl10.caption:=checklistbox2.Items;
tu:=tu+' select @w10=convert(float,sum(i.weight+i.wtemp)/1000),@b10=convert(float,sum(wBooked)/1000) '+
' from vproductdata v,inventory i,stores s where i.productNo=v.productNo and s.storeNo=i.storeNo and s.status=''n'' and s.compNo="0000" and (i.weight<>0 or i.wtemp<>0 or i.wbooked<>0 or wway<>0) '+
' and gperm2=@gperm2 and grade=@grade and '+
' (productName="" '+te+') and sizespec="'+checklistbox2.Items+'" update #te set w10=@w10,b10=@b10 where gperm2=@gperm2 and grade=@grade ';
end;
end;
end;
end;
end;
dmInventory.qinvd.sql.Add(te+')' );
dmInventory.qinvd.sql.Add(' open c_InvStruc fetch next from c_InvStruc into @gperm2,@grade '+
' while (@@fetch_status=0) begin insert #te (gperm2,grade) values(@gperm2,@grade) ');
dmInventory.qinvd.sql.Add(tu);
dmInventory.qinvd.sql.Add(' select @wRoll=convert(float,sum(i.weight+i.wtemp)/1000),@bRoll=convert(float,sum(wBooked)/1000) '+
' from vproductdata v,inventory i,stores s where i.productNo=v.productNo and s.storeNo=i.storeNo and s.status=''n'' and s.compNo="0000" and (i.weight<>0 or i.wtemp<>0 or i.wbooked<>0 or wway<>0) '+
' and (v.type="3" or v.type="4") and gperm2=@gperm2 and grade=@grade and '+
' (productName="" '+te+')'+' update #te set wRoll=@wRoll,bRoll=@bRoll where gperm2=@gperm2 and grade=@grade ' );
dmInventory.qinvd.sql.Add(' select @inv=convert(float,sum(i.weight+i.wtemp)/1000),@invb=convert(float,sum(wBooked)/1000) '+
' from vproductdata v,inventory i,stores s where i.productNo=v.productNo and s.storeNo=i.storeNo and s.status=''n'' and s.compNo="0000" and (i.weight<>0 or i.wtemp<>0 or i.wbooked<>0 or wway<>0) '+
' and gperm2=@gperm2 and grade=@grade and '+
' (productName="" '+te+')'+' update #te set inv=@inv,invb=@invb where gperm2=@gperm2 and grade=@grade ' );
dmInventory.qinvd.sql.Add(' fetch next from c_InvStruc into @gperm2,@grade end '+
'close c_InvStruc deallocate c_InvStruc select *,inv-invb least from #te ' );
// showmessage(dmInventory.qinvd.sql.text);
dmInventory.qinvd.open;
frmrepd.QuickRep1.Preview;