SqlJoinType in query object dataitem in not working
Hi Experts,
SqlJoinType in query object dataitem in not working. No matter I was using SqlJoinType=FullOuterJoin; SqlJoinType=LeftOuterJoin;or SqlJoinType=RightOuterJoin; It always return the result as SqlJoinType=InnerJoin.
In Item Table, we have a new item Test1
In Item Ledger Entry. It doesn't have the new item 1001. Because it does not have any inventory change.
So I group by the Item by Item No and Location Code in Item Ledger Entry and full outer join on item table.
we could not found 1002 in the result.

Actually I tried, left join, right join and switch the position of these two table. All get the same result. Did I just used the Query Object in the wrong way?
AL 2.1.69331
@RuiningFan could you please provide a sample that used to work in C/AL and the equivalent that does not work in AL?
Sorry for the delay. I have update the post. I'm not sure this is caused by using the query object in a wrong way.
Hi, I have the same issues in AL, trying left, right or fullouterjoin did not work. The query is fairly simple, just to get dimension 3 value from dimension set entry in Item Ledger Entry table
query 50009 "ItemTracking" { QueryType = Normal; Caption = 'Item_Tracking'; elements { dataitem(Item_Ledger_Entry; "Item Ledger Entry") { DataItemTableFilter = "Serial No." = filter ('<>''''');
column(Entry_No; "Entry No.") { Caption = 'Entry No'; }
column(Item_No; "Item No.") { Caption = 'Item No'; }
column(Posting_Date; "Posting Date") { Caption = 'Posting Date'; }
column(Entry_Type; "Entry Type") { Caption = 'Entry Type'; }
column(Document_Date; "Document Date") { Caption = 'Document Date'; }
column(Document_No; "Document No.") { Caption = 'Document No'; }
column(Document_Type; "Document Type") { Caption = 'Document Type'; }
column(External_Document_No; "External Document No.") { Caption = 'External Document No'; }
column(Location_Code; "Location Code") { Caption = 'Location Code'; }
column(Lot_No; "Lot No.")
{
}
column(Serial_No; "Serial No.")
{
}
column(Source_Type; "Source Type") { Caption = 'Source Type'; }
column(Source_No; "Source No.") { Caption = 'Source No'; }
column(Quantity; Quantity) { Caption = 'Quantity'; }
column(Purchase_Amount_Actual; "Purchase Amount (Actual)") { Caption = 'Purchase Amount'; }
column(Sales_Amount_Actual; "Sales Amount (Actual)") { Caption = 'Sales Amount'; }
column(Cost_Amount_Actual; "Cost Amount (Actual)") { Caption = 'Cost Amount'; }
column(Cost_Centre; "Global Dimension 1 Code") { Caption = 'Cost Centre'; }
column(Department; "Global Dimension 2 Code") { Caption = 'Department'; }
dataitem(DimSet3; "Dimension Set Entry")
{
SqlJoinType = LeftOuterJoin;
DataItemTableFilter = "Dimension Code" = const ('SALES CHANNEL');
DataItemLink = "Dimension Set ID" = Item_Ledger_Entry."Dimension Set ID";
column(Sales_Channel; "Dimension Value Code") { Caption = 'Sales Channel'; }
}
}
}
}
The same query in CAL is working
LEFT JOIN, the filter applied before or after
Hi, I'm experiencing the same problem. I guess the problem lays in the combination of Option of the DataItemLink
This is the case in my Cronus company:
- Item 1000 has a
Sales Unit of MeasureofGR - The
Item Unit of MeasureGRfor this Item 1000 is missing So I created a Query object to verify this:
query 50001 "Item Unit of Measure"
{
QueryType = Normal;
elements
{
dataitem(Item; Item)
{
DataItemTableFilter = "No." = filter ('1000');
column(No_; "No.") { }
column(Description; Description) { }
column(Base_Unit_of_Measure; "Base Unit of Measure") { }
column(Sales_Unit_of_Measure; "Sales Unit of Measure") { }
dataitem(Item_Unit_of_Measure; "Item Unit of Measure")
{
SqlJoinType = LeftOuterJoin;
DataItemLink = "Item No." = Item."No.", Code = Item."Sales Unit of Measure";
DataItemTableFilter = "Qty. per Unit of Measure" = filter (> 0);
column(Code; Code) { }
column(Qty__per_Unit_of_Measure; "Qty. per Unit of Measure") { }
}
}
}
trigger OnBeforeOpen()
begin
end;
}
Unfortunately, the output of my Query doesn't return any records. When I'm translating my Query Object to an SQL Query, this is how my Query looks:
SELECT [No_]
,[Description]
,[Base Unit of Measure]
,[Sales Unit of Measure]
,iuom.Code
,iuom.[Qty_ per Unit of Measure]
FROM [CRONUS BELGIË NV$Item] item
LEFT OUTER JOIN [CRONUS BELGIË NV$Item Unit of Measure] iuom
ON iuom.[Item No_] = item.No_
AND iuom.Code = item.[Sales Unit of Measure]
WHERE [No_] = '1000'
AND iuom.[Qty_ per Unit of Measure] > 0
GO
But again, no output here

So What goes wrong exactly? When you place filters in the ON clause on a LEFT JOIN, the filter is applied before the results are joined to the outer table. When you apply a filter in the WHERE clause, it happens after the LEFT JOIN has been applied.
So when I change my SQL Query to:
SELECT [No_]
,[Description]
,[Base Unit of Measure]
,[Sales Unit of Measure]
,iuom.Code
,iuom.[Qty_ per Unit of Measure]
FROM [CRONUS BELGIË NV$Item] item
LEFT OUTER JOIN [CRONUS BELGIË NV$Item Unit of Measure] iuom
ON iuom.[Item No_] = item.No_
AND iuom.Code = item.[Sales Unit of Measure]
AND iuom.[Qty_ per Unit of Measure] > 0
WHERE [No_] = '1000'
GO
... I get the output I wanted.

Unfortunately, when I try to adapt my Query object in AL, I get a Syntax error, '=' expected (AL(AL0104) [17,121])
query 50001 "Item Unit of Measure"
{
QueryType = Normal;
elements
{
dataitem(Item; Item)
{
DataItemTableFilter = "No." = filter ('1000');
column(No_; "No.") { }
column(Description; Description) { }
column(Base_Unit_of_Measure; "Base Unit of Measure") { }
column(Sales_Unit_of_Measure; "Sales Unit of Measure") { }
dataitem(Item_Unit_of_Measure; "Item Unit of Measure")
{
SqlJoinType = LeftOuterJoin;
DataItemLink = "Item No." = Item."No.", Code = Item."Sales Unit of Measure", "Qty. per Unit of Measure" > 0;
column(Code; Code) { }
column(Qty__per_Unit_of_Measure; "Qty. per Unit of Measure") { }
}
}
}
trigger OnBeforeOpen()
begin
end;
}
So my guess is that there should be a syntax update allowing us to add "Qty. per Unit of Measure" > 0 in the DataItemLink as it is allowed in an native SQL query.
Kind regards, Job Louage
Can you still reproduce the issue on the latest 15.X based release? On a very simple example of query join type seem to work for me on 15.x. The DataItemTableFilter is applied on the result of the join and not to the RHS of the join https://docs.microsoft.com/en-us/dynamics-nav/dataitemtablefilter-property