开票订单行选择查询.sql 796 B

123456789
  1. select *,t2.freceivedamount,tp.fprojectname,sdate.closedate1,(isnull(t2.freceivedamount,0)-isnull(t1.finvoiceamount,0)) as fcaninvoiceamount from saorderdetail t1
  2. inner join saorder_receivedview t2 on t1.siteid=t2.siteid and t1.saorderdetailid=t2.saorderdetailid and isnull(t2.freceivedamount,0)>isnull(t1.finvoiceamount,0)
  3. inner join saorder sa on t1.fparentid = sa.saorderid and sa.fpayagentnum=$fagentnum$ and sa.fstatus in('ÉóºË','¹Ø±Õ')
  4. left join tproject tp on sa.fprojectnum = tp.fprojectnum and sa.siteid=tp.siteid
  5. left join sainvoice_closedate sdate on sdate.fsourceid = t1.saorderdetailid
  6. where t1.siteid=$siteid$
  7. and not exists(
  8. select *from tinvoiceapplyorder where siteid=$siteid$ and tinvoiceapplyid=$tinvoiceapplyid$ and saorderdetailid=t1.saorderdetailid
  9. ) and $where$