我现在有一个字段为规格:500克/袋(车,箱),还有一个字段为单位,公斤(吨),现在要使用计算字段,把输入的数量:折合成多少袋(车,箱)比如说,我输入数量为500,单位为公斤,那么计算字段就这样计算  (500公斤/500克)袋(车,箱)

解决方案 »

  1.   

    select 规格,单位,单位/规格*1000 from 表
      

  2.   

    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
      

  3.   

    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 表
      

  4.   

    我觉得建立一个换算公司表。
    采用Haiwer(海阔天空) 的方法,不过在前面加一个序号,然后根据你的表中数据进行换算,加入代码即可。就好像做财务软件那样建立公式表。