strSql.Append(" select * into #T1 from( SELECT f.GId,f.BsNo,f.FeeStatus, ");
strSql.Append(" (select top 1 EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99024 and EnumValueID=f.FeeStatus) as FeeStatus_Ref, ");
strSql.Append(" (select top 1 NAME from vMsTruckFeeType where NAME=f.FeeName) as FeeName_Ref, ");
strSql.Append(" (select top 1 EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99020 and EnumValueID=f.FeeType) as FeeType_Ref ");
strSql.Append(" ,f.FeeDescription,f.enterdate,f.CustomerName as CustomerName_Ref,f.Unit,f.UnitPrice,f.Quantity, case f.feetype when 1 then f.Amount else 0 end amount_ys, ");
strSql.Append(" case f.feetype when 1 then 0 else f.Amount end amount_yf, case f.feetype when 1 then f.Amount*f.exchangerate else 0 end amount_rmbys, ");
strSql.Append(" case f.feetype when 1 then 0 else f.Amount*f.exchangerate end amount_rmbyf, f.Currency,f.ExChangerate ");
strSql.Append(" ,f.Remark,m.ContractNo,m.CUSTNO HTH,(select top 1 seller from import_main where CONTRACTNO=m.BSNO) seller ");
strSql.Append(" ,m.CUSTOMERNAME buyer,m.MBLNO Billno,m.Vessel,m.VOYNO Voyage,(select top 1 dbo.trimdate(Sailingdate) from import_main where CONTRACTNO=m.BSNO) Sailingdate ");
strSql.Append(" ,dbo.trimdate(m.ETD) ArrivalDate,(select top 1 ContainerNo from import_main where CONTRACTNO=m.BSNO) ContainerNo ");
strSql.Append(" ,(select top 1 SealNo from import_main where CONTRACTNO=m.BSNO) SealNo,dbo.trimdate(m.CREATETIME) creattime ");
strSql.Append(" ,(select top 1 showname from [user] where gid=f.enteroperator) createuser, case f.feetype when 1 then f.SETTLEMENT else 0 end SETTLEMENT_ys, ");
strSql.Append(" case f.feetype when 1 then 0 else f.SETTLEMENT end SETTLEMENT_yf, case f.feetype when 1 then (f.Amount-f.SETTLEMENT)*f.exchangerate else 0-(f.Amount-f.SETTLEMENT)*f.exchangerate end remain, ");
strSql.Append(" case f.feetype when 1 then dbo.f_danhao(f.gid,5) else dbo.f_danhao(f.gid,4) end [AC_AD], dbo.f_danhao(f.gid,1) [CR_DR], debitno,dbo.f_danhao(f.gid,6) [Inv], ");
strSql.Append(" f.ACCDATE,f.ISVOU,f.VOUCHERNO,f.AUDITDATE,(select top 1 showname from [user] where gid=f.auditoperator) auditoperator ,dbo.f_VOUNO(f.gid) VOUNO,dbo.f_str(f.bsno) cargoname ");
strSql.Append(" ,(select top 1 name from company c where c.gid=m.CORPID) company ,m.op ");
strSql.Append(" from ch_fee f ");
strSql.Append(" left join v_op_bs m on (f.bsno=m.bsno) ");
strSql.Append(" '',0,'','','','','','','','','','','','','','',sum(SETTLEMENT_ys),sum(SETTLEMENT_yf),sum(remain),'','','','','','','','','','','','','' from #T1 order by bsno,FeeType_Ref,FeeName_Ref, ");