create sql query based flow filter

catiamatos1991
Member Posts: 158
HI everyone,
I'm trying to create the sql query code based on a flow filter calc formula.
The formula is "Sum("Detailed Vendor Ledg. Entry".Amount WHERE (Vendor Ledger Entry No.=FIELD(Entry No.),Posting Date=FIELD(Date Filter),Excluded from calculation=CONST(No)))" and I "convert" this to
Select Sum([E18375$Detailed Vendor Ledg_ Entry].[Amount]) as 'Valor pendente' FROM [E18375$Detailed Vendor Ledg_ Entry] INNER JOIN [E18375$Vendor Ledger Entry] ON [E18375$Detailed Vendor Ledg_ Entry].[Vendor Ledger Entry No_] = [E18375$Vendor Ledger Entry].[Entry No_] WHERE [E18375$Detailed Vendor Ledg_ Entry].[Excluded from calculation] = 0 AND [E18375$Detailed Vendor Ledg_ Entry].[Document No_]='1707NC006'
AND YEAR([E18375$Detailed Vendor Ledg_ Entry].[Posting Date])>=2017
The problem is I get the value "Valor pendente" equals to "1838" instead of "10" like the image below.

I follow this example i found online to create my sql query..
Sum("Detailed Cust. Ledg. Entry"."Amount (LCY)" WHERE (Cust. Ledger Entry No.=FIELD(Entry No.),Entry Type=FILTER(Initial Entry),Posting Date=FIELD(Date Filter)))
Select Sum([Amount (LCY)] FROM [Detailed Cust. Ledg. Entry]
INNER JOIN
[Cust. Ledg. Entry]
ON
[Detailed Cust. Ledg. Entry].[Entry No.] = [Cust. Ledg. Entry].[Entry No.]
WHERE
[Detailed Cust. Ledg. Entry].[Entry Type] = "Initial Entry"
I'm trying to create the sql query code based on a flow filter calc formula.
The formula is "Sum("Detailed Vendor Ledg. Entry".Amount WHERE (Vendor Ledger Entry No.=FIELD(Entry No.),Posting Date=FIELD(Date Filter),Excluded from calculation=CONST(No)))" and I "convert" this to
Select Sum([E18375$Detailed Vendor Ledg_ Entry].[Amount]) as 'Valor pendente' FROM [E18375$Detailed Vendor Ledg_ Entry] INNER JOIN [E18375$Vendor Ledger Entry] ON [E18375$Detailed Vendor Ledg_ Entry].[Vendor Ledger Entry No_] = [E18375$Vendor Ledger Entry].[Entry No_] WHERE [E18375$Detailed Vendor Ledg_ Entry].[Excluded from calculation] = 0 AND [E18375$Detailed Vendor Ledg_ Entry].[Document No_]='1707NC006'
AND YEAR([E18375$Detailed Vendor Ledg_ Entry].[Posting Date])>=2017
The problem is I get the value "Valor pendente" equals to "1838" instead of "10" like the image below.

I follow this example i found online to create my sql query..
Sum("Detailed Cust. Ledg. Entry"."Amount (LCY)" WHERE (Cust. Ledger Entry No.=FIELD(Entry No.),Entry Type=FILTER(Initial Entry),Posting Date=FIELD(Date Filter)))
Select Sum([Amount (LCY)] FROM [Detailed Cust. Ledg. Entry]
INNER JOIN
[Cust. Ledg. Entry]
ON
[Detailed Cust. Ledg. Entry].[Entry No.] = [Cust. Ledg. Entry].[Entry No.]
WHERE
[Detailed Cust. Ledg. Entry].[Entry Type] = "Initial Entry"
0
Answers
-
As a starting point the predicate
..ON [E18375$Detailed Vendor Ledg_ Entry].[Entry No_] = [E18375$Vendor Ledger Entry].[Entry No_] ..
should rather go like thisON [E18375$Detailed Vendor Ledg_ Entry].[Vendor Ledger Entry No_] = [E18375$Vendor Ledger Entry].[Entry No_]...
Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-030 -
Even with this query I don't get the correct result
select 'E18375' as Empresa, [E18375$Detailed Vendor Ledg_ Entry].[Posting Date], [E18375$Detailed Vendor Ledg_ Entry].[Document No_], [E18375$Detailed Vendor Ledg_ Entry].[Vendor No_], [E18375$Detailed Vendor Ledg_ Entry].Amount, (Select Sum([Amount (LCY)]) FROM [E18375$Detailed Vendor Ledg_ Entry] INNER JOIN [E18375$Vendor Ledger Entry] ON [E18375$Detailed Vendor Ledg_ Entry].[Entry No_] = [E18375$Vendor Ledger Entry].[Entry No_] WHERE [E18375$Detailed Vendor Ledg_ Entry].[Excluded from calculation]=0 AND [E18375$Detailed Vendor Ledg_ Entry].[Amount]>0) as 'Valor pendente' from [E18375$Vendor Ledger Entry] inner join [E18375$Detailed Vendor Ledg_ Entry] on [E18375$Detailed Vendor Ledg_ Entry].[Vendor Ledger Entry No_]=[E18375$Vendor Ledger Entry] .[Entry No_] where [E18375$Vendor Ledger Entry].[Open]=1 and [E18375$Detailed Vendor Ledg_ Entry].[Document No_]='1707NC006' group by [E18375$Detailed Vendor Ledg_ Entry].[Posting Date], [E18375$Detailed Vendor Ledg_ Entry].[Document No_], [E18375$Detailed Vendor Ledg_ Entry].[Vendor No_], [E18375$Detailed Vendor Ledg_ Entry].[Vendor Ledger Entry No_], [E18375$Detailed Vendor Ledg_ Entry].[Amount] having sum([E18375$Detailed Vendor Ledg_ Entry].[Amount])>0
It returns a amount of "3510098.20000000000000000000" for "Valor Pendente" instead of "10". Maybe the group by clause is wrong? or the having.. i don't get it
maybe the problem is the flow filter conversion...0 -
[Topic moved from 'NAV/Navision Classic Client' forum to 'SQL General' forum]
Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
PS: AND [E18375$Detailed Vendor Ledg_ Entry].[Document No_]='1707NC006'
Shouldn't that filter in the document no. in the vendor ledger entry? Because in the detailed it can have multiple values for 1 vendor ledger entry.
And I would turn around the query:
SELECT dvle.SUM(Amount)
FROM "Vendor Ledger Entry" vle
WITH(READUNCOMMITTED) // to avoid putting sharelocks on the table while reading
INNER JOIN "Detailed Vendor Legd_ Entry" dvle
WITH(READUNCOMMITTED) // to avoid putting sharelocks on the table while reading
ON (dvle."Vendor Ledger Entry No_" = vle."Entry No_")
AND (dvle."Excluded From Calculation" = 0)
AND (dvle.[Posting Date] >= '2017-01-01')
AND (dvle.[Posting Date] <= '2017-12-31');
WHERE vle.[Document No_]='1707NC006'
# AVOID AT ALL COST : YEAR("Some Date") = 2017. This forces SQL to scan the whole table or index!.
PS2: the INNER JOIN with the "Excluded from calculation" could have as a result that vendor ledger entries are skipped if No detailed ledger entries are selected for a vendor ledger entryRegards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
Hi @kriki, I try your query and it returns 1838 (same value as Amount) and not the 10 (as the image below)
SELECT SUM([E18375$Detailed Vendor Ledg_ Entry].[Amount]) FROM [E18375$Vendor Ledger Entry] WITH(READUNCOMMITTED) INNER JOIN [E18375$Detailed Vendor Ledg_ Entry] WITH(READUNCOMMITTED) ON ([E18375$Detailed Vendor Ledg_ Entry].[Vendor Ledger Entry No_] = [E18375$Vendor Ledger Entry].[Entry No_]) AND ([E18375$Detailed Vendor Ledg_ Entry].[Excluded From Calculation] = 0) AND ([E18375$Detailed Vendor Ledg_ Entry].[Posting Date] >= '2017-01-01') AND ([E18375$Detailed Vendor Ledg_ Entry].[Posting Date] <= '2017-12-31') WHERE [E18375$Vendor Ledger Entry].[Document No_]='1707NC006'
With green should be the correct value...
Here's the nav table info
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