The system I maintain seems to slow down quite a bit every few days, and I assume it’s from a bad query somewhere.
From what I can tell, I’ve narrowed the issue down to a page or two. Here’s the query on the page that I think is causing the issue.
select a.s_purchase_order as order_id, a.order_type, a.nobackorder, a.order_note, a.note, a.rqst_dlvry_date, b.customer_name ,c.store_name,(c.store_name + ',' + isnull(c.address1 + ',', ' ') + isnull(c.city + ',', ' ') + isnull(c.state_cd+ ',', ' ') + isnull( c.zipcode, ' ')) as store_info, d.supplier_account
from VW_CustomerOrder a, Customer b, Store c, eligible_supplier d
where a.customer = c.customer
and a.store = c.store
and a.customer = b.customer
and c.customer *= d.customer
and c.store *= d.store
and a.supplier *= d.supplier
and a.purchase_order = @order_id
and a.customer = @customer_id
and a.store=@store_id
and a.supplier = @supplier_id
Is there something obvious there that would be very slow or cause the system to slow over time?
what about do some inner joins to solve this, check your base and see index and foreign keys for those table, this always is helpful in querys and performance