繁体   English   中英

如何选择NOT IN值(Formula Crystal报表)

[英]How to Select NOT IN Value (Formula Crystal Reports)

我在SQL Server中有以下查询:

select * from  ARInvoices ar 
left join ARInvoiceDetails det on ar.InvoiceID = det.InvoiceID
where ar.InvoiceID not in (select InvoiceID from CashReceiptInvoices ) 
and det.SubmitTo = 1 and VoucherStatus = 0 and det.TransactionType = 1

我想通过Crystal Reports XI中的公式来使用它,但是我很难在不使用它的情况下使用。我使用<>,但结果却是空的。

您可以使用“ anti-join”(带有约束的LEFT JOIN ,其中要加入表的IS NULL )来消除NOT IN

select * from  ARInvoices ar 
left join ARInvoiceDetails det on ar.InvoiceID = det.InvoiceID
left join CashReceiptInvoices cri on ar.InvoiceID = cri.InvoiceID -- new JOIN
where cri.InvoiceID is null                                       -- no match
and det.SubmitTo = 1 and VoucherStatus = 0 and det.TransactionType = 1

我不知道水晶报表在所有,但如果这只是NOT IN您遇到麻烦,但你的LEFT JOIN工作正常,那么你可以只添加一个LEFT JOIN

select * 
from  ARInvoices ar 
left join ARInvoiceDetails det on ar.InvoiceID = det.InvoiceID
left join CashReceiptInvoices cri on ar.InvoiceID = cri.InvoiceID
where  cri.InvoiceID IS NULL
   and det.SubmitTo = 1 
   and VoucherStatus = 0 
   and det.TransactionType = 1

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM