Using inner select to get total quantity

void InitializeDataView()
{
    From = Orders;

    Orders.Columns.Add(V_HasOrderDetails);
    V_HasOrderDetails.Name = @"isnull((
Select max(1)
From dbo.[Order Details] 
Where OrderID = Orders.OrderID
),0)";
            
    Orders.Columns.Add(TotalQuantity);
    TotalQuantity.Name = @"isnull((
Select sum(Quantity)
From dbo.[Order Details] 
Where OrderID = Orders.OrderID
),0)";

    OrderBy = Orders.SortByPK_Orders; 

Then we remove the Quantity inner class and it's reference in the OnEnterRow

protected override void OnEnterRow()
{
-   TotalQuantity.Value = 0;
-   if (V_HasOrderDetails)
-       Cached<GetTotalQuantity>().Run();
    _layout.Orders.WriteTo(_ioPrinter);
} 

Another way to do this, without hard coded SQL statements, would be to use the InnerSelectHelper. See Using SQL inner select


Help us improve, Edit this page on GitHub
or email us at info@fireflymigration.com