Question

SQL view doesn't return all records.

  • 12 January 2024
  • 12 replies
  • 162 views

Userlevel 2
Badge

I created a simple SQL view for table INLocationStatus in customization "TestStockLogMasterInventoryReport"

 

Create VIEW [dbo].[LogoMasterInventoryReport]

AS

SELECT        TOP (100) PERCENT LS.CompanyID,  LS.InventoryID,  LS.SubItemID, LS.SiteID, LS.LocationID,

                     LS.QtyOnHand,   LS.QtyOnHand AS [TotalQtyonHand]

      

FROM        dbo.INLocationStatus AS LS

 

The table should have 212623 records. But the SQL view only returns 212213 records.

I created GI for INLocationStatus, and it return 212623 records. The GI for LogoMasterInventoryReport view only return 212213 records. 

Does anyone know there is any records restrictions for SQL view in Acumatica? This is for 2023 R2.

 

Thanks.

 


12 replies

Userlevel 7
Badge +12

Very strange but then Top (100) Percent is an oddity i presume you are trying to order the SQL view?

Can you try it removing the this and just use a straight Select and see how many records you are getting

Userlevel 2
Badge

I removed it and use straight select, still the same.

 

Create VIEW [dbo].[LogoMasterInventoryReport]
AS
SELECT         LS.CompanyID,  LS.InventoryID,  LS.SubItemID, LS.SiteID, LS.LocationID,
                     LS.QtyOnHand,   LS.QtyOnHand AS [TotalQtyonHand]
      
FROM        dbo.INLocationStatus AS LS

Userlevel 7
Badge +12

Hmm ok anonther thought does yout GI based on table INLocationStatus have any other tables in the GI. If so remove them and check the result.

Userlevel 2
Badge

We initially have group clause in the view and link multiple tables in the GI. We didn’t get the expected result. So I simplified view to just select fields without any group, and only include this view in GI without other tables. And I found the view doesn’t return all records.

Userlevel 7
Badge +12

I dont believe it is view that is the issue. I would trust it more than anything else. Can you tip both sets of results in to Excel and use a VLookup to find the extra/missings one.

The GI giving the result of 212623 does this only have one table in it the INLocationStatus

Userlevel 2
Badge

Please see the screenshot below. The left screen is GI from the SQL view LogoMasterInventoryReport, that’s the only table in the GI. It has total 212213 records. The last record InventoryID stops at 19064.

The right screen is the GI from INLocationstatus inner join to InventoryItem. It has 212626 records. There are more records after InventoryID 19064. 

I don’t know why the SQL view stops at the InventoryID 19064.

 

 

Userlevel 7
Badge +12

@junmao01 Very weird would you mind sharing the GI with me and i will run it and the script on one of my datasets.

Userlevel 4
Badge

@junmao01  This is going to sound counter-intuitive, but IMO, the issue is not your SQL view, but the GI with the INNER JOIN.
I think you are seeing too many rows returned in the INNER JOIN GI with the Inventory. (IE. you are returning duplicates in SQL in that GI).
What you might try is on your INNER JOIN GI, set grouping to LS.InventoryID and see then if the two GI’s return the same number of rows.  Or possibly using a LEFT JOIN instead.
What happens when you run those SQL commands natively in SSMS?
Below is an example where I took your SQL view statement and ran it against my DB natively, and then also ran it with an INNER JOIN on Inventory items.  You can see where the two SQL commands return different numbers of data sets.

IF you want to JOIN your INLocationStatus to your InventoryItem table as a SQL view, I have found it much better to use the following type of SQL construct. You can see the results in the third screenshot below.
    SELECT        TOP (100) PERCENT LS.CompanyID,  LS.InventoryID,  LS.SubItemID, LS.SiteID, LS.LocationID,
                                    LS.QtyOnHand,   LS.QtyOnHand AS [TotalQtyonHand],
                                    INV.[InventoryID],INV.[InventoryCD]
    FROM        dbo.INLocationStatus AS LS
    OUTER APPLY (
          SELECT TOP(1) *
          FROM [dbo].[InventoryItem]
          WHERE [dbo].[InventoryItem].[InventoryID] = LS.[InventoryID]
    ) INV
    WHERE LS.[CompanyID] = 2

 

 

Userlevel 2
Badge

I don’t have any JOIN in my SQL view and GI. The SQL view is just select from one table INLocationStatus, and the GI only select this SQL view. This is in Acumatica sandbox. So I don’t have access to SSMS.

Userlevel 2
Badge

I find the problem. From 2023 R2 the INSiteStatus and INLocationStatus are projection DAC now. The old records are still exist in the table. But new records will be added to actual table INSiteStatusByCostCenter and INLocationStatusByCostCenter. 

Userlevel 7
Badge +8

@junmao01 wow nice find, tricky one! 

Userlevel 7
Badge

Thank you for sharing your solution with the community @junmao01!

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved