strSql.Append(" order by "+sortstring.Replace("OPSTATUS","(SELECT TOP 1 STATUS FROM V_OP_STATUS WITH (NOLOCK) WHERE BSNO=B.BSNO ORDER BY COMPTIME DESC,INPUTTIME DESC)"));
strSql.Append(" order by "+sortstring.Replace("DRINVSTATUS"," CASE WHEN ISNULL(I.TTLINVDR,0)=0 THEN '未开票' ELSE CASE WHEN ISNULL(I.TTLINVDR,0)=ISNULL(I.TTLDR,0) THEN '已开票' ELSE '部分开票' END END "));
strSql.Append(" order by "+sortstring.Replace("DRDUISTATUS"," CASE WHEN ISNULL(I.TTLDUIDR,0)=0 THEN '未对账' ELSE CASE WHEN ISNULL(I.TTLDUIDR,0)=ISNULL(I.TTLDR,0) THEN '已对账' ELSE '部分对账' END END "));
sortstring=sortstring.Replace("OPSTATUS","(SELECT TOP 1 STATUS FROM OP_STATUS WITH (NOLOCK) WHERE BSNO=OP_APPLY.BSNO ORDER BY COMPTIME DESC,INPUTTIME DESC)");
strSql.Append(" order by "+sortstring);
if(sortstring.ToUpper().IndexOf("OPSTATUS")>=0)
strSql.Append(" order by "+sortstring.Replace("OPSTATUS","(SELECT TOP 1 STATUS FROM V_OP_STATUS WITH (NOLOCK) WHERE BSNO=OP_APPLY.BSNO ORDER BY COMPTIME DESC,INPUTTIME DESC)"));
strSql.Append(" order by "+sortstring.Replace("FEESTATUSREF"," FEESTATUS "));
elseif(sortstring.ToUpper().IndexOf("AMEND")>=0)
strSql.Append(" order by "+sortstring.Replace("AMEND"," CASE WHEN (SELECT COUNT(*) FROM OP_AMEND WHERE PARENTID=OP_APPLY.BSNO)>0 THEN 1 ELSE 0 END "));
strSql.Append(" order by "+sortstring.Replace("DRINVSTATUS"," CASE WHEN ISNULL(I.TTLINVDR,0)=0 THEN '未开票' ELSE CASE WHEN ISNULL(I.TTLINVDR,0)=ISNULL(I.TTLDR,0) THEN '已开票' ELSE '部分开票' END END "));
strSql.Append(" order by "+sortstring.Replace("DRDUISTATUS"," CASE WHEN ISNULL(I.TTLDUIDR,0)=0 THEN '未对账' ELSE CASE WHEN ISNULL(I.TTLDUIDR,0)=ISNULL(I.TTLDR,0) THEN '已对账' ELSE '部分对账' END END "));
strSql.Append(" order by "+sortstring.Replace("BSCUSTNO"," (select TOP 1 CUSTNO from v_op_bs_no where BSNO=OP_APPLY.MASTERNO) "));
else
{
sortstring=sortstring.Replace("OPSTATUS","(SELECT TOP 1 STATUS FROM OP_STATUS WITH (NOLOCK) WHERE BSNO=OP_APPLY.BSNO ORDER BY COMPTIME DESC,INPUTTIME DESC)");