Get Serial No. Information Records, which were in stock on a given date

robbonick
Member Posts: 40
Hi,
I am working on a project where the Serial No. Information table (Table 6504) has been customised, and is used quite heavily.
I need to be able to find what items from this table, had a quantity in stock > 0 at a given date.
So to do this I am trying to use a NAV query.
In the past this was done using some flowfields and flowfilters, but this is quite slow to return the results.
Our hope was we would be able to reproduce this using a NAV Query to speed the process up, however we are having some trouble.
I can create this fine in SQL itself, and this is essentially what we are trying to reproduce:
The NAV code used a FlowField "Inventory at Date" which is almost identical to the standard field "Inventory", however it uses an extra filter for "Date Filter" on "Posting Date" in Item Ledger Entry. So in code we could write
So we created a Query, which joins on "Item No", "Variant Code" & "Serial No." to "Item Ledger Entry" and looks like this:

Then in the code we would set our filters on the query to filter for:
However we get way more entries returned than we expect, and it is quite slow.
We know the SQL is correct, and the old code returns the same amount of records.
I have tried using some of the different Join options in the Query, but they do not seem to help.
It just seems like this is not possible to do with a NAV Query.
I was hoping someone may have some advice?
I am working on a project where the Serial No. Information table (Table 6504) has been customised, and is used quite heavily.
I need to be able to find what items from this table, had a quantity in stock > 0 at a given date.
So to do this I am trying to use a NAV query.
In the past this was done using some flowfields and flowfilters, but this is quite slow to return the results.
Our hope was we would be able to reproduce this using a NAV Query to speed the process up, however we are having some trouble.
I can create this fine in SQL itself, and this is essentially what we are trying to reproduce:
SELECT sni.[Serial No_], sub.Qty_in_Stock FROM dbo.[SFS$Serial No_ Information] AS sni WITH (NOLOCK) OUTER APPLY ( SELECT SUM(ile.Quantity) AS Qty_in_Stock FROM dbo.[SFS$Item Ledger Entry] AS ile WITH (NOLOCK) WHERE ile.[Posting Date] <= '28 Aug 2018' AND ile.[Serial No_] = sni.[Serial No_] AND ile.[Variant Code] = sni.[Variant Code] AND ile.[Item No_] = sni.[Item No_] ) sub WHERE sub.Qty_in_Stock = 1;
The NAV code used a FlowField "Inventory at Date" which is almost identical to the standard field "Inventory", however it uses an extra filter for "Date Filter" on "Posting Date" in Item Ledger Entry. So in code we could write
SerialNoInformation.SETRANGE("Date Filter", 0D, ParamDate); SerialNoInformation.SETRANGE("Inventory at Date", 1); SerialNoInformation.FINDSET;
So we created a Query, which joins on "Item No", "Variant Code" & "Serial No." to "Item Ledger Entry" and looks like this:

Then in the code we would set our filters on the query to filter for:
Query.SETFILTER("Posting_Date", '..%1', ParamDate); Query.SETFILTER("Sum_Quantity", '>%1', 0);
However we get way more entries returned than we expect, and it is quite slow.
We know the SQL is correct, and the old code returns the same amount of records.
I have tried using some of the different Join options in the Query, but they do not seem to help.
It just seems like this is not possible to do with a NAV Query.
I was hoping someone may have some advice?
0
Best Answer
-
To anyone interested, we ended up using two separate queries to solve this.0
Answers
-
Any ideas? I am surprised something so simple doesn't seem to be possible with a Query.0
-
To anyone interested, we ended up using two separate queries to solve this.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions