Không thực sự chắc chắn cho dù tôi có thể rời tham gia kết quả mà tôi nhận được từ một cây thánh giá áp dụng chức năng:Left tham gia vào một truy vấn với một chéo áp dụng
select
iv.invoiceno
,w.warehouse
,iv.invoicedate
,iv.invoicedesc
,iv.status
,iv.billingstart as [BillingFrom]
,iv.billingend as [BillingTo]
,CAST((iv.invoicesubtotal) as NUMERIC(38,2))as [Sub-Total]
,CAST((((iv.invoicesubtotal+iv.invoicetax)-iv.invoicetotal)) as NUMERIC(38,2)) as [Discount]
,CAST((iv.invoicetax) as NUMERIC(38,2)) as [SalesTax]
,CAST((iv.invoicetotal) as NUMERIC(38,2)) as [Total]
,d.deal
,d.dealno
,ivt.orderno
,ivt.rectype
,ivt.rectypedisplay
,RTRIM(ivt.masterno) as [ICode]
,ivt.description as [ICodeDesc]
,ivt.fromdate as [From]
,ivt.todate as [To]
,CAST((ivt.days) as NUMERIC(38,2)) as [days]
,CAST(ivt.qty as NUMERIC(38,0)) as [qty]
,CAST((ivt.cost) as NUMERIC(38,2)) as [UnitCost]
,CAST((ivt.rate) as NUMERIC(38,2)) as [rate]
,CAST((ivt.daysinwk)as NUMERIC(38,2)) as [D/W]
,CAST((ivt.discountamt)as NUMERIC(38,2)) as [Discount]
,CAST((ivt.extended)as NUMERIC(38,2)) as [extended]
,(CASE WHEN ivt.taxable='T' then 'YES' else 'NO' END)as [Taxable]
,ivt.category
,(CASE WHEN (ivt.cost > 0 and ivt.rectype='R') THEN CAST((ivt.revenuebase) as NUMERIC (38,2)) ELSE 0 END) as [subrevenue] from invoice iv
inner join deal d on d.dealid=iv.dealid
inner join invoiceitemview ivt on iv.invoiceid=ivt.invoiceid and iv.invoiceno=ivt.invoiceno
inner join warehouse w on w.locationid=iv.locationid and w.inactive<>'T'
left join category c on c.categoryid=ivt.categoryid
left join ordernoteview n on ivt.orderid=n.orderid and n.billing ='T' where iv.locationid='00009V5H' and iv.invoiceno='H513369' and iv.status in ('CLOSED', 'PROCESSED') and iv.nocharge<>'T' order by iv.invoiceno, iv.invoicedate,c.category,ivt.masterno
Tôi muốn thêm một trái tham gia với truy vấn này:
select tot.gldate, tot.glno, tot.glacctdesc,
tot.debit,tot.credit,tot.glaccountid from invoice ivt cross apply dbo.funcglforinvoice(ivt.invoiceid, null, null) as tot where ivt.invoiceno='H513369'
nhưng khi tôi làm điều đó nó mang lại cho tôi nhiều bản ghi hơn thì có nghĩa vụ phải có.
Điều này đã được thực hiện trong một thời gian. Về cơ bản, truy vấn áp dụng chéo bên trong tạo ra 204 mục và tôi muốn được tham gia với các mục từ truy vấn chính; nhưng tôi đang làm sai điều gì đó không chắc chắn chính xác là gì. Trợ giúp sẽ được đánh giá cao.
Bạn có mệnh đề WHERE hay điều gì đó để bạn không trả lại mọi bản ghi từ bảng hóa đơn? Và tôi hiểu bạn đã chạy riêng lẻ, vì vậy bạn biết rằng nó không trả lại quá 204 bản ghi cho toàn bộ phần này: (chọn iii.invoiceid, tot.gldate, tot.glno, tot.glacctdesc, tot.debit, tot. tín dụng, glaccountid từ hóa đơn iii chéo áp dụng dbo.funcglforinvoice (iii.invoiceid, null, null) như tot) – criticalfix