i,specs,weight,Quantity:integer; specs:=0; weight:=0; Quantity:=0; i:=Pos('克',Query1.FieldbyName('规格').AsString); if i>0 then Specs=inttostr(copy(Query1.FieldbyName('规格').AsString,1,i+1));i:=Pos('公斤',Query1.FieldbyName('单位').AsString); if i>0 then weight=inttostr(copy(Query1.FieldbyName('单位').AsString,1,i+1));i:=Pos('吨',Query1.FieldbyName('单位').AsString); if i>0 then weight=1000*inttostr(copy(Query1.FieldbyName('单位').AsString,1,i+1));if Specs*Weight>0 then Quantity:=Specs*1000/Weight
select 规格,单位,case when charindex('公斤',单位)>0 then substring(单位,1,charindex('公斤',单位)-1)/substring(规格,1,charindex('克',规格)-1)*1000 when charindex('吨',单位)>0 then substring(单位,1,charindex('吨',单位)-1)/substring(规格,1,charindex('克',规格)-1)*1000000 end as 计算字段 from 表
specs:=0;
weight:=0;
Quantity:=0;
i:=Pos('克',Query1.FieldbyName('规格').AsString);
if i>0 then Specs=inttostr(copy(Query1.FieldbyName('规格').AsString,1,i+1));i:=Pos('公斤',Query1.FieldbyName('单位').AsString);
if i>0 then weight=inttostr(copy(Query1.FieldbyName('单位').AsString,1,i+1));i:=Pos('吨',Query1.FieldbyName('单位').AsString);
if i>0 then weight=1000*inttostr(copy(Query1.FieldbyName('单位').AsString,1,i+1));if Specs*Weight>0 then
Quantity:=Specs*1000/Weight
采用Haiwer(海阔天空) 的方法,不过在前面加一个序号,然后根据你的表中数据进行换算,加入代码即可。就好像做财务软件那样建立公式表。