qty on hand using sift tables from sql

ara3n
Member Posts: 9,258
Hello. A lot companies use outside systems to grab qty on hand for items. Most of the use item ledger. This store procedure uses the sift tables just like navision
Just change Company_Name to your company name and run the store procedure.
CREATE PROC GetQuantity @ItemNo varchar(20)='%',@Variant varchar(10)='%', @Location varchar(10)='%'
AS
SELECT f2 as ItemNo, SUM(s12) AS Quantity
FROM [Company_Name$32$0]
WHERE (bucket = 4) AND (f8 like @Location ) and (f5402 Like @Variant)
GROUP BY f2
HAVING (f2=@ItemNo)
Just change Company_Name to your company name and run the store procedure.
CREATE PROC GetQuantity @ItemNo varchar(20)='%',@Variant varchar(10)='%', @Location varchar(10)='%'
AS
SELECT f2 as ItemNo, SUM(s12) AS Quantity
FROM [Company_Name$32$0]
WHERE (bucket = 4) AND (f8 like @Location ) and (f5402 Like @Variant)
GROUP BY f2
HAVING (f2=@ItemNo)
0
Comments
-
Very cool! That works only as long as nobody touches the SIFT key in Navision. Don't you think it would be safer to do something similar from the Item Ledger?0
-
yes you could use the item ledger instead of sift table. It's not effecient to use item ledger when you have million of records.0
-
I think reading FlowFields from SQL can be generalized into a general template.
1) Choose an Entry table. Put down the number of the table, this number will be called A.
2) Look at Keys.
3) Assume that you want a FlowField for a key that has SumIndexFields AND SIFTLevels, these are the "popular" key, however, if your choice doesn't have either of them, you have to create both.
4) Count (from 0) the number of keys that have both, and put down which one is the key you want - f.e. if it's the second, put down 1. This will be called B.
5) Drill into SIFTLevels and choose the level that contains all the flowfilters
you wish to filter for. Put down the Bucket number, this will be called C.
6) Now go to the table definition. Put down the number of the field which is
related to the master data, the foreign key (I mean Item No., G/L Account No., Customer No.) etc. this will be called D.
7) Put down the number of the Decimal field you want to sum for (it must be included in the SumIndexField). It will be called E.
8 ) Put down the numbers of all flowfilters you wish to filter for, these will be called F,G,H...
The SQL template is the following:select fD, sum(sE) from dbo.[Company_Name$A$B] where bucket=C --and you can filter for F,G,H here group by fD
For example, to show the G/L balance by G/L Account No:
- A = table numbr = 17
- B = the first key with both SumIndexFields and SIFTLevels counted from zero = 0
- C = bucket, if you don't need filtering for Posting Date, its = 1
- D = the field number of G/L Account No. = 3
- E = the field number of Amount = 17
So the query is:select f3, sum(s17) from dbo.[Company_Name$17$0] where bucket=1 group by f3
Although for reporting, as Analysis Services is for free, throwing all f-fields into dimensions and all S-fields into measures and throwing it into Excel looks like an easier solution...
Is there a text representation of an OLAP cube in a similar way like a Navision object exported to Text? Because if yes, I could write a utility to autogenerate these cubes and then we would have powerful Navision reporting in Excel for free.
Do It Yourself is they key. Standard code might work - your code surely works.0 -
ara3n wrote:yes you could use the item ledger instead of sift table. It's not effecient to use item ledger when you have million of records.
In general in SQL it is a good idea to redesign the keys to your needs.
E.g.
In case you don't use variants, you can create a new key or put property SQLIndex of 1 key = "Item No.,Location Code,Open"
This SQL-key can be used for a lot of Navision-keys.Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
No doubt kriki, I've suggested the same idea to a client a few years ago. Navision is using sift tables for a reason, and I just put the code just in case somebody wanted to know. I know I did a few years back.0
-
[Topic moved from Navision Tips & Tricks forum to SQL Performance forum]Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
How does this method perform compared to just using C/Front and running calcfields?0
-
you could run sql profiler and see the sql statement. my guess it runs similar statement.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