Hello tech experts, users and fellow novices like myself.
I'm in need of some help with my query text - when it runs it apparently spikes our server and hogs resource (but our dba won't see fit to letting us use anything other than MS Query for querying our database, with the queries usually being refreshed within MS Excel spreadsheets).
I can't actually paste in the exact code at present (Citrix server is down) but essentially the query contains four selects nested within the select command - two of which are selecting different records from the same table
My question is can anyone help me optimise the code to help prevent the resource spike that apparently manifests when the query is run... btw the InvSales table in the code appears to be a dba-created view and not an actual table (and I think this is where the resource-eating begins but the dba won't confirm this for me)
Background - don't know if its relevant but hey!
SQL Server 2000 (dunno SP)
Syspro 6.09 (Frontend database app)
Query purpose:
Existing report shows slow / non-moving stock items.
Data is selected from a view "InvSales" which gathers stock-on-hand and sales-usage information for a particular client warehouse, and inner joins this by the item Code field (key field) to the InvMaster table to show item description, packsize and product-class.
New requirements:
a) latest receipt date of a stock item (contained within the InvReceipts table)
b) the number of pallet spaces occupied (contained within the InvBins table)
c) the subdivision of the item's productclass - stored as a customformfield in CustomFormData table
d) the named owner for that product classs / subdivision - which is again stored as a customformfield in CustomFormData table.
The latter two fields are a pain but are there due to existing database design constraints and the understandable reluctance of the dba in not allowing the existing productclass field to be linked to any other table with spare fields large enough to accommodate the class owner-name and subdivision.
I hope you haven't fallen asleep.
So I've had to take the original query - an MS Query which was graphical drag-n-drop wizard-built where the JOIN info was originally built into the WHERE clause.... and change it to a query that contains several SELECTs nested within the main SELECT, and specify the join type and conditions.
I sincerely hope someone can help guide a novice in this matter...
I'm in need of some help with my query text - when it runs it apparently spikes our server and hogs resource (but our dba won't see fit to letting us use anything other than MS Query for querying our database, with the queries usually being refreshed within MS Excel spreadsheets).
I can't actually paste in the exact code at present (Citrix server is down) but essentially the query contains four selects nested within the select command - two of which are selecting different records from the same table
Code:
SELECT InvSales.Warehouse, InvSales.Code, InvMaster.Descript, InvMaster.ExtraDesc, InvMaster.PackSize, InvSales.Last12wksSales, InvWarehouse.QtyOnHand, (SELECT MAX(LastReceivedDate) FROM InvReceipts WHERE Code = InvSales.Code), (SELECT COUNT (Bin) FROM InvBins WHERE Code = InvSales.Code), (SELECT AlphaValue FROM CustomFormData WHERE Keyfield = InvSales.Code AND FieldName = 'Owner'), (SELECT AlphaValue FROM CustomFormData WHERE Keyfield = InvSales.Code AND FieldName = 'SubDiv')
FROM InvSales INNER JOIN InvMaster ON InvSales.Code = InvMaster.Code, INNER JOIN InvWarehouse ON InvSales.Code = InvWarehouse.Code AND InvSales.Warehouse = InvWarehouse.Warehouse
WHERE InvSales.Warehouse = 'BC'
ORDER BY InvSales.Code
My question is can anyone help me optimise the code to help prevent the resource spike that apparently manifests when the query is run... btw the InvSales table in the code appears to be a dba-created view and not an actual table (and I think this is where the resource-eating begins but the dba won't confirm this for me)
Background - don't know if its relevant but hey!
SQL Server 2000 (dunno SP)
Syspro 6.09 (Frontend database app)
Query purpose:
Existing report shows slow / non-moving stock items.
Data is selected from a view "InvSales" which gathers stock-on-hand and sales-usage information for a particular client warehouse, and inner joins this by the item Code field (key field) to the InvMaster table to show item description, packsize and product-class.
New requirements:
a) latest receipt date of a stock item (contained within the InvReceipts table)
b) the number of pallet spaces occupied (contained within the InvBins table)
c) the subdivision of the item's productclass - stored as a customformfield in CustomFormData table
d) the named owner for that product classs / subdivision - which is again stored as a customformfield in CustomFormData table.
The latter two fields are a pain but are there due to existing database design constraints and the understandable reluctance of the dba in not allowing the existing productclass field to be linked to any other table with spare fields large enough to accommodate the class owner-name and subdivision.
I hope you haven't fallen asleep.
So I've had to take the original query - an MS Query which was graphical drag-n-drop wizard-built where the JOIN info was originally built into the WHERE clause.... and change it to a query that contains several SELECTs nested within the main SELECT, and specify the join type and conditions.
I sincerely hope someone can help guide a novice in this matter...