Acumatica BQL查询多次使用同一个表

时间:2016-02-12 17:03:14

标签: acumatica

我正在尝试使用同一个表多次构建BQL查询。在下面的示例中,我尝试使用POVendorInventory,因为它与项目和每个项目仓库的默认值相关(在查询中列出两次的表的原因)。

如何在Acumatica BQL查询中执行此操作。我目前的疑问是:

foreach (PXResult<INItemSite, InventoryItem, POVendorInventory, POVendorInventory> result in PXSelectJoin<INItemSite,
        InnerJoin<InventoryItem, On<INItemSite.inventoryID, Equal<InventoryItem.inventoryID>>,
        LeftJoin<POVendorInventory, On<InventoryItem.inventoryID, Equal<POVendorInventory.inventoryID>
            , And<InventoryItem.preferredVendorID, Equal<POVendorInventory.vendorID>
            , And<InventoryItem.preferredVendorLocationID, Equal<POVendorInventory.vendorLocationID>>>>,
        LeftJoin<POVendorInventory, On<INItemSite.preferredVendorID, Equal<POVendorInventory.vendorID>,
                And<INItemSite.inventoryID, Equal<POVendorInventory.inventoryID>>>>>>,
            Where<InventoryItem.stkItem, Equal<boolTrue>>,
            OrderBy<Asc<INItemSite.inventoryID, Asc<INItemSite.siteID>>>>.Select(graph))
        {
            var poVendorInventoryDefault = (POVendorInventory)result[2];
            var poVendorInventorySite = (POVendorInventory)result[3];
        }

执行查询时,上述结果会出现以下错误: 相关名称&#39; POVendorInventory&#39;在FROM子句中多次指定。

MS SQL中的类似查询是:

SELECT  s.InventoryID ,
    i.InventoryCD ,
    s.SiteID ,
    n.SiteCD ,
    s.PreferredVendorID ,
    s.PreferredVendorOverride ,
    pd.VendorID ,
    pd.AddLeadTimeDays ,
    ps.VendorID ,
    ps.AddLeadTimeDays
    FROM    dbo.INItemSite s
    INNER JOIN dbo.InventoryItem i ON s.CompanyID = i.CompanyID
                                      AND s.InventoryID = i.InventoryID
    INNER JOIN dbo.INSite n ON s.CompanyID = n.CompanyID
                               AND s.SiteID = n.SiteID
    LEFT JOIN dbo.POVendorInventory pd ON i.CompanyID = pd.CompanyID
                                          AND i.InventoryID = pd.InventoryID
                                          AND i.PreferredVendorID = pd.VendorID
                                          AND i.PreferredVendorLocationID = pd.VendorLocationID
    LEFT JOIN dbo.POVendorInventory ps ON s.CompanyID = ps.CompanyID
                                          AND s.InventoryID = ps.InventoryID
                                          AND s.PreferredVendorID = ps.VendorID
    WHERE   s.CompanyID = 2
    AND i.StkItem = 1
    ORDER BY s.InventoryID, s.SiteID

以下情况也不起作用。

[Serializable]
public class POVendorInventoryTwo : POVendorInventory{}

PXResult<INItemSite, InventoryItem, POVendorInventoryTwo, POVendorInventory> result in PXSelectJoin<INItemSite,
        InnerJoin<InventoryItem, On<INItemSite.inventoryID, Equal<InventoryItem.inventoryID>>,
        LeftJoin<POVendorInventoryTwo, On<InventoryItem.inventoryID, Equal<POVendorInventoryTwo.inventoryID>
            , And<InventoryItem.preferredVendorID, Equal<POVendorInventoryTwo.vendorID>
            , And<InventoryItem.preferredVendorLocationID, Equal<POVendorInventoryTwo.vendorLocationID>>>>,
        LeftJoin<POVendorInventory, On<INItemSite.preferredVendorID, Equal<POVendorInventory.vendorID>,
                And<INItemSite.inventoryID, Equal<POVendorInventory.inventoryID>>>>>>,
            Where<InventoryItem.stkItem, Equal<boolTrue>>,
            OrderBy<Asc<INItemSite.inventoryID, Asc<INItemSite.siteID>>>>.Select(graph)

但正如答案所提到的,您需要使用POVendorInventoryTwo进行第二次使用,如下所示:

PXResult<INItemSite, InventoryItem, POVendorInventory, POVendorInventoryTwo> result in PXSelectJoin<INItemSite,
        InnerJoin<InventoryItem, On<INItemSite.inventoryID, Equal<InventoryItem.inventoryID>>,
        LeftJoin<POVendorInventory, On<InventoryItem.inventoryID, Equal<POVendorInventory.inventoryID>
            , And<InventoryItem.preferredVendorID, Equal<POVendorInventory.vendorID>
            , And<InventoryItem.preferredVendorLocationID, Equal<POVendorInventory.vendorLocationID>>>>,
        LeftJoin<POVendorInventoryTwo, On<INItemSite.preferredVendorID, Equal<POVendorInventoryTwo.vendorID>,
                And<INItemSite.inventoryID, Equal<POVendorInventoryTwo.inventoryID>>>>>>,
            Where<InventoryItem.stkItem, Equal<boolTrue>>,
            OrderBy<Asc<INItemSite.inventoryID, Asc<INItemSite.siteID>>>>.Select(graph)

1 个答案:

答案 0 :(得分:4)

我过去所做的是DAC的子类并查询它。

这样的事情:

'use strict';
const Hapi       = require('hapi');
const server = new Hapi.Server({
  cache: [
    {
      name: 'redisCache',
      engine: require('catbox-redis'),
      host: 'redis',
      partition: 'cache',
      password: 'devpassword'
    }
  ]
});
module.exports = server;

然后在您的BQL中,使用此子类版本作为第二个值。