嗨我遇到一些BQL语法问题我想要实现的是一个BQL语句,如下面的SQL,在where子句中使用嵌套子查询。
arr.inject(0,:+)
#=> 0
arr.inject(:+)
#=> nil
如果可以,这可以在BQL中编写吗?
以下是我目前的情况,但这并不正确我收到语法错误
SELECT * FROM ARInvoice I
WHERE (SELECT COUNT(*) FROM ARAdjust A WHERE I.RefNbr = A.AdjdRefNbr) > 0
感谢
答案 0 :(得分:5)
您有两种方法可以实现此目的。
使用子查询:
您可以在ARInvoice中添加未绑定的计算字段(PXDBScalar)
要在BQL中添加子查询,必须在属性级别执行此操作。因为您想要查询另一个表,PXDBScalar,将是最佳选择。如果您想查询同一记录的其他字段,PXDBCalced会更合适。有关高级SQL属性的更多信息,请参阅使用高级SQL属性下的T200和帮助下的Acumatica帮助 - > Acumatica框架 - > API参考 - >属性 - >字段的临时SQL。
延长ARInvoice (V5.1及以下)
public class ARInvoiceExtension : PXCacheExtension<ARInvoice>
{
public abstract class lastPaymentOrderNbr : IBqlField
{
}
#region LastPaymentOrderNbr
[PXString]
[PXUIField(DisplayName = "Last Payment Order Nbr.")]
[PXDBScalar(typeof(Search<ARAdjust.adjdOrderNbr,
Where<ARAdjust.adjdDocType, Equal<ARInvoice.docType>,
And<ARAdjust.adjdRefNbr, Equal<ARInvoice.refNbr>>>,
OrderBy<Desc<ARAdjust.adjgDocDate>>>))]
public string LastPaymentOrderNbr { get; set; }
#endregion
}
ARInvoice已在 V5.2 中添加了一个新字段,以获取上一个付款日期,因此您无需再添加另一个:
public abstract class lastPaymentDate : PX.Data.IBqlField
{
}
protected DateTime? _LastPaymentDate;
/// <summary>
/// The date of the most recent payment associated with this document.
/// </summary>
[PXDate()]
[PXDBScalar(typeof(Search<ARAdjust.adjgDocDate,
Where<ARAdjust.adjdDocType, Equal<ARInvoice.docType>,
And<ARAdjust.adjdRefNbr , Equal<ARInvoice.refNbr>>>,
OrderBy<Desc<ARAdjust.adjgDocDate>>>))]
[PXUIField(DisplayName = "Last Payment Date")]
public virtual DateTime? LastPaymentDate
{
get
{
return this._LastPaymentDate;
}
set
{
this._LastPaymentDate = value;
}
}
您的PXSelect将如下所示:
V5.1及以下
public PXSelect<ARInvoice, Where<ARInvoiceExtension.lastPaymentOrderNbr, IsNotNull>> InvoicesTest;
V5.2
public PXSelect<ARInvoice, Where<ARInvoice.lastPaymentDate, IsNotNull>> InvoicesTest;
表格上的内部联接
您可以简单地添加没有ARAdjust的内部联接和过滤记录,而不是查询它。然后,您可以按关键字段进行分组,以避免重复。
public PXSelectJoinGroupBy<ARInvoice,
InnerJoin<ARAdjust, On<ARAdjust.adjdRefNbr, Equal<ARInvoice.refNbr>,
And<ARAdjust.adjdDocType, Equal<ARInvoice.docType>>>>,
Where<ARAdjust.adjdOrderNbr, IsNotNull>,
Aggregate<GroupBy<ARInvoice.docType,
GroupBy<ARInvoice.refNbr>>>> InvoicesTest;