Acumatica where子句中的BQL子查询

Acumatica where子句中的BQL子查询,acumatica,Acumatica,您好,我遇到了一些问题,一些BQL语法我想要实现的是一个BQL语句,如下面的SQL语句,在where子句中嵌套了子查询 SELECT * FROM ARInvoice I WHERE (SELECT COUNT(*) FROM ARAdjust A WHERE I.RefNbr = A.AdjdRefNbr) > 0 这在BQL中是否可能?如果可能,我将如何编写 下面是我目前得到的,但这是不正确的,我有语法错误 PXSelect<PX.Objects.AR.ARInvo

您好,我遇到了一些问题,一些BQL语法我想要实现的是一个BQL语句,如下面的SQL语句,在where子句中嵌套了子查询

  SELECT * FROM ARInvoice I 
WHERE (SELECT COUNT(*) FROM ARAdjust A WHERE I.RefNbr = A.AdjdRefNbr) > 0
这在BQL中是否可能?如果可能,我将如何编写

下面是我目前得到的,但这是不正确的,我有语法错误

   PXSelect<PX.Objects.AR.ARInvoice,
        Where<PXSelectGroupBy<PX.Objects.AR.ARAdjust, Where<PX.Objects.AR.ARAdjust.adjdRefNbr, Equal<PX.Objects.AR.ARInvoice.refNbr>, Aggregate<Count>>, Greater<Zero>>>>.Select(new PXGraph());
PXSelect.Select(新建PXGraph());

谢谢

您有两个选项来实现这一点

使用子查询:

您可以在语音中添加一个未绑定的计算字段(PXDBScalar)

要在BQL中添加子查询,必须在属性级别进行。因为您想查询另一个表,PXDBScalar是最好的选择。如果要查询同一记录的其他字段,PXDBCalced将更合适。有关高级SQL属性的更多信息,请参阅T200下的使用高级SQL属性和Acumatica的帮助下的帮助->Acumatica框架->API参考->属性->特殊SQL字段

扩展ARInvoice(V5.1及以下版本)

公共类扩展:PXCacheExtension
{
公共抽象类lastpaymentdernbr:IBqlField
{
}
#地区最新地址
[字符串]
[PXUIField(DisplayName=“上次付款单编号”)]
[PXDBScalar(类型(搜索))]
公共字符串lastpaymentdernbr{get;set;}
#端区
}
V5.2中的ARInvoice添加了一个新字段,以获取最后的付款日期,因此您无需再添加一个字段:

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;
    }
}
公共抽象类lastPaymentDate:PX.Data.IBqlField
{
}
保护日期时间_最后付款日期;
/// 
///与此文档关联的最近一次付款的日期。
/// 
[PXDate()]
[PXDBScalar(类型(搜索))]
[PXUIField(DisplayName=“上次付款日期”)]
公共虚拟日期时间?最后付款日期
{
得到
{
返回此。\u LastPaymentDate;
}
设置
{
这是。_LastPaymentDate=值;
}
}
然后,您的PXSelect将如下所示:

V5.1及以下版本

public px选择InvoicesTest;
V5.2

public px选择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;
public px选择joingroupby InvoicesTest;

Excellant thankyou-我只是检查了一下语音余额是否小于LineTotal。但使用最后一个付款日期会简单得多
public PXSelect<ARInvoice, Where<ARInvoiceExtension.lastPaymentOrderNbr, IsNotNull>> InvoicesTest;
public PXSelect<ARInvoice, Where<ARInvoice.lastPaymentDate, IsNotNull>> InvoicesTest;
        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;