strSql.Append(",(SELECT TOP 1 STATUS+' '+ CONVERT(varchar(100),COMPTIME, 20) FROM OP_STATUS WHERE BSNO=v_op_bill.BSNO AND STTYPE='2' ORDER BY COMPTIME DESC,INPUTTIME DESC) as OPSTATUS ");
strSql.Append(",(SELECT TOP 1 COMMISSIONRATE FROM V_Client_ACCDATE WHERE SHORTNAME=v_op_bill.CUSTOMERNAME ORDER BY BGNDATE DESC) as COMMISSIONRATE ");
strSql.Append(",(SELECT TOP 1 STATUS+' '+ CONVERT(varchar(100),COMPTIME, 20) FROM OP_STATUS WHERE BSNO=v_op_bill.BSNO AND STTYPE='2' ORDER BY COMPTIME DESC,INPUTTIME DESC) as OPSTATUS ");
strSql.Append(",(SELECT TOP 1 COMMISSIONRATE FROM V_Client_ACCDATE WHERE SHORTNAME=v_op_bill.CUSTOMERNAME ORDER BY BGNDATE DESC) as COMMISSIONRATE ");
strSql.Append(",(SELECT TOP 1 STATUS+' '+ CONVERT(varchar(100),COMPTIME, 20) FROM OP_STATUS WHERE BSNO=v_op_bill.BSNO AND STTYPE='2' ORDER BY COMPTIME DESC,INPUTTIME DESC) as OPSTATUS ");
strSql.Append(",(SELECT TOP 1 COMMISSIONRATE FROM V_Client_ACCDATE WHERE SHORTNAME=v_op_bill.CUSTOMERNAME ORDER BY BGNDATE DESC) as COMMISSIONRATE ");
strSql.Append(",(SELECT TOP 1 STATUS+' '+ CONVERT(varchar(100),COMPTIME, 20) FROM OP_STATUS WHERE BSNO=v_op_bill.BSNO AND STTYPE='2' ORDER BY COMPTIME DESC,INPUTTIME DESC) as OPSTATUS ");
strSql.Append(",(SELECT TOP 1 COMMISSIONRATE FROM V_Client_ACCDATE WHERE SHORTNAME=v_op_bill.CUSTOMERNAME ORDER BY BGNDATE DESC) as COMMISSIONRATE ");
strSql.Append(",(SELECT TOP 1 STATUS+' '+ CONVERT(varchar(100),COMPTIME, 20) FROM OP_STATUS WHERE BSNO=v_op_bill.BSNO AND STTYPE='2' ORDER BY COMPTIME DESC,INPUTTIME DESC) as OPSTATUS ");
strSql.Append(",(SELECT TOP 1 COMMISSIONRATE FROM V_Client_ACCDATE WHERE SHORTNAME=v_op_bill.CUSTOMERNAME ORDER BY BGNDATE DESC) as COMMISSIONRATE ");
strSql.Append(",SALEDEPT,(select [NAME] from [company] where GID=v_op_bill.SALECORPID) as SALECORP,(select top 1 SHOWNAME from VW_user where userid in (select top 1 op from workflow_using where TYPENO='602' and bsno=v_op_bill.bsno)) BILLFEEOP ");//
sql=sql+getAndConSql(sql,customNo," BILLNO like '%" +customNo+"%'");
sql=sql+getAndConSql(sql,customNo," cm.BILLNO like '%" +customNo+"%'");
varBH=form.findField('BH').getValue();
sql=sql+getAndConSql(sql,BH," EXISTS(select 1 from ch_fee_do where BILLNO=cm.BILLNO and EXISTS(select 1 from v_op_bill where bsno=ch_fee_do.BSNO and (CUSTNO like '%"+BH+"%' or MBLNO like '%"+BH+"%' or HBLNO like '%"+BH+"%') ))");