我正在尝试基于流过滤器计算公式创建sql查询代码
所以我有“供应商分类帐输入”表,其中包含两个名为“金额”和“剩余金额”的重要字段。
这两个字段都是flowfiltes,基于与其他表格的公式计算(在本例中为Detailed Vendor Ledger Entry)
剩余金额:"Sum("Detailed Vendor Ledg. Entry".Amount WHERE (Vendor Ledger Entry No.=FIELD(Entry No.),Posting Date=FIELD(Date Filter),Excluded from calculation=CONST(No)))"
所以我将“剩余金额”转换为此sql查询
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
问题是我得到的值“Valor pendente”等于“1838”而不是“10”,如下图所示。
我按照这个例子在网上找到了创建我的SQL查询..
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"
我的完整查询如下:
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].[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].[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
所以你似乎只有2个你感兴趣的表:
[E18375 $详细供应商Ledg_ Entry] [E18375 $供应商分类帐分录]
您的查询中似乎缺少[Entry Type] =“Initial Entry”:
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].[Entry No_] = [E18375$Vendor Ledger Entry].[Entry No_]
WHERE [E18375$Detailed Vendor Ledg_ Entry].[Excluded from calculation] = 0
AND [E18375$Detailed Vendor Ledg_ Entry].[Entry Type] = "Initial Entry";
我猜你的一个表中有一条记录,另一条记录有很多记录,而且过滤效果不正常。
我在这里走出困境,因为所写的查询没有多大意义。但我想你想得到每一行的细节线,以及供应商的总数。
这样做:
select 'E18375' as Empresa,
L4.[Posting Date],
L4.[Document No_],
L4.[Vendor No_],
L4.Amount,
VT as 'Valor pendente'
from [E18375$Vendor Ledger Entry] L3
inner join [E18375$Detailed Vendor Ledg_ Entry] L4 on L4.[Vendor Ledger Entry No_]=L3.[Entry No_]
join (
Select [Vendor No_], Sum([Amount (LCY)]) as VT
FROM [E18375$Detailed Vendor Ledg_ Entry] L1
INNER JOIN [E18375$Vendor Ledger Entry] L2 ON L1.[Entry No_] = L2.[Entry No_]
WHERE L1.[Excluded from calculation]=0 AND L1.[Amount]>0
group by [Vendor No_]
) VendorTotal on VendorTotal.[Vendor No_]=L4.[Vendor No_]
where L3.[Open]=1 and L4.[Document No_]='1707NC006'
and VT>0