I tried setting the timeout property to 0 and that made no difference at all. The website is used for internal processes only, so I don't have a problem with the user having to wait for 2 minutes. Below is the query that I am using. Running in query analyzer it took 111 seconds to run and returned 71 rows. If I eliminate the derived table, it still takes over 30 seconds to run. 2 of the tables in the query have over 500,000 rows and the other table (inv_loc) has over 2,500,000 rows. Thank you for looking at this!
select
inv_mast.item_id
,inv_mast.item_desc
,inv_loc.inv_min
,inv_loc.inv_max
,free_stock = inv_loc.qty_on_hand - inv_loc.qty_allocated
,qty_needed_for_min = inv_loc.inv_min - (inv_loc.qty_on_hand - inv_loc.qty_allocated - inv_loc.qty_backordered)
,qty_needed_for_max = inv_loc.inv_max - (inv_loc.qty_on_hand - inv_loc.qty_allocated - inv_loc.qty_backordered)
,extra_stock.extra_stock
,location_needing_stock = inv_loc.location_id
,location_with_extra_stock
,inventory_supplier.cost
from
inv_mast
inner join inv_loc on inv_mast.inv_mast_uid = inv_loc.inv_mast_uid
inner join inventory_supplier on inv_mast.inv_mast_uid = inventory_supplier.inv_mast_uid and inv_loc.primary_supplier_id = inventory_supplier.supplier_id
inner join (
select
inv_mast.inv_mast_uid
,inv_mast.item_id
,extra_stock = inv_loc.qty_on_hand - inv_loc.qty_allocated - inv_loc.qty_backordered - inv_loc.inv_max
,location_with_extra_stock = location_id
from
inv_mast
inner join inv_loc on inv_mast.inv_mast_uid = inv_loc.inv_mast_uid
where
inv_loc.qty_on_hand - inv_loc.qty_allocated - inv_loc.qty_backordered - inv_loc.inv_max > 0)
extra_stock on inv_mast.inv_mast_uid = extra_stock.inv_mast_uid
where
inv_loc.qty_on_hand - inv_loc.qty_allocated - inv_loc.qty_backordered < inv_loc.inv_min