for xml path

来源:互联网 发布:淘宝好评加分规则 编辑:程序博客网 时间:2024/05/16 06:17
select 
b.dates,b.ontime,a.billno as rfbillno,a.billsn as rfbillsn,b.billcode,
a.goodsid,a.packid,d.unit,b.ruleid as rfruleid,b.summaries,a.num,
a.taxprice,a.taxamount,
case when a.TaxPrice = 0 then 0 else a.jiesje / a.Taxprice end as yjsnum,
a.jiesje as yjiesje,
case when a.TaxPrice = 0 then 0 else a.PTaxAmount / a.TaxPrice end as PNum,
a.PTaxAmount,e.goodscode,
e.goodsname,0 as jiesje, 'N' as issettle,b.entid,100 as dedrate,
(h.num - h.InvoiceNum) as yInvoiceNum,h.InvoiceNum,
m.val as InvoiceCode
from apGoodsDt a
join apGoodsMt b on a.billno = b.billno and a.entid=b.entid
join purindt h on a.billno = h.billno and a.billsn = h.billsn and a.entid = h.entid
left join PGPrice d on a.packid = d.packid and a.entid = d.entid
join goodsdoc e on a.goodsid = e.goodsid and a.entid = e.entid
left join (
select a.rfbillno,a.rfbillsn, [val]=stuff((
select ','+[InvoiceCode] from InvoiceDt b 
join InvoiceMt c on b.billno = c.billno 
where b.rfbillno = a.rfbillno
and a.rfbillsn = b.rfbillsn
and c.ruleid = '31s3evan4k6wwy22'
for xml path('')),1,1,'') from InvoiceDt a
group by a.rfbillno,a.rfbillsn
) m on a.billno = m.rfbillno and a.billsn = m.rfbillsn
#if(typeof jsywlx != "undefined") {
#if(jsywlx.length > 0) {
 #if(jsywlx == "销售") {
    left join (
select a.Dates,b.GoodsId,b.AngleId
from SALEOUTMT a
inner join (
select GoodsId,AngleId,MIN(BillNo) as MinBillNo
from SALEOUTDT
where EntId = :_entid
group by GoodsId,AngleId
) b on a.BillNo = b.MinBillNo
where a.EntId = :_entid
) g on h.GoodsId = g.GoodsId and h.AngleId = g.AngleId
 #}
#}
#}
where b.rfid = :SuppliersId
and b.entid = :_entid
and abs(a.PTaxAmount) < abs(a.TaxAmount)
and a.goodsid = :goodsid
and b.payorgid = :PayOrgId
and a.issettle = 'N'
#if(typeof jsywlx != "undefined") {
#if(jsywlx.length > 0) {
#if(jsywlx == "入库") {
#if(jszq == "天") {
and datediff(d,b.dates,CONVERT(varchar(100), GETDATE(), 23)) >= :jisz
#} else if(jszq == "月") {
and DATEADD(M,-1 * :jisz,CONVERT(varchar(100), GETDATE(), 23)) >= b.dates
#} else if(jszq == "当月") {
and MONTH(b.dates) = MONTH(GETDATE())
#}
#} else if(jsywlx == "销售") {
#if(jszq == "天") {
and datediff(dd,g.dates,CONVERT(varchar(100), GETDATE(), 23)) >= :jisz
#} else if(jszq == "月") {
and datediff(mm,g.Dates,getdate()) >= :jisz
#} else if(jszq == "当月") {
and MONTH(g.dates) = MONTH(GETDATE())
#}
and g.dates is not null
#}
#}
#}
order by b.dates, b.ontime
0 0
原创粉丝点击