I know that we should not be using While select statements in a display method(on a form).
But I have a requirement where I need to use a while select, but as we know it is causing serious performance issues.
Any alternatives?
Code Snippet:
select InventSiteId, InventLocationId from inventDim
where inventDim.inventDimId == this.InventDimId;
while select InventDimId from inventDimSelection
where inventDimSelection.InventSiteId == inventDim.InventSiteId
&& inventDimSelection.InventLocationId == inventDim.InventLocationId
{
select sum(AvailPhysical) from inventSum
where inventSum.ItemId == this.ItemId
&& inventSum.InventDimId == inventDimSelection.InventDimId;
sumPhy+= inventSum.AvailPhysical;
}
return sumPhy;
I am selecting the location/site based on the InventDimId and then using those to fetch all the records from InventDim and eventually InventSum.
the reason behind all the above code and not just using the below code:
select sum(AvailPhysical) from inventSum
where inventSum.ItemId == this.ItemId
&& inventSum.InventDimId == this.InventDimId;
Because, there can be too many InventDimId’s for a single site/warehouse combination.
Any help would be appreciated.
- Sourabh