Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Looong running query
Message
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Looong running query
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01346813
Message ID:
01346813
Views:
39
Hi All,

Is there a way to tune this query somehow. It returns expected results but it takes over 6 hours to complete....
Thank you,
DAniel
Select prtmst.prtnum as SKU, pitems.descr,
		pitems.status, prtmst.prtfam as family,   
	(select rtstr1 
		from njsql.wmsnj.dbo.poldat poldat, njsql.wmsnj.dbo.locmst locmst 
		where poldat.rtstr1 = locmst.stoloc		
		and poldat.rtnum1 = 1 
		and poldat.polcod = 'STORE-ASG-LOC' 
		and poldat.polvar = 'prtnum' 
		and replace(poldat.polval, '----|', '') = prtmst.prtnum) as LocAssigned, 
	(select maxqvl 
		from njsql.wmsnj.dbo.locmst 
		where stoloc = (select rtstr1 
							from njsql.wmsnj.dbo.poldat poldat, njsql.wmsnj.dbo.locmst locmst 
							where poldat.rtstr1 = locmst.stoloc 
							and poldat.rtnum1 = 1 
							and poldat.polcod = 'STORE-ASG-LOC' 
							and poldat.polvar = 'prtnum' 
							and replace(poldat.polval, '----|', '') = prtmst.prtnum)) as LocCapacity, 
	ftpmst.untlen as [length], ftpmst.untwid as width, ftpmst.unthgt as height, history.demcan4 as [4 Wks Sales], 
	(select count (*) 
		from njsql.wmsnj.dbo.dlytrn dlytrn 
		where dlytrn.actcod = 'CASRPL' 
		and dlytrn.prtnum = prtmst.prtnum) as [4 Wks Repln], 
	history.demcan26 as [26 Wks Sales], 
	(select count (*) 
		from njsql.wmsnj_arch.dbo.dlytrn arch_dlytrn 
		where arch_dlytrn.actcod = 'CASRPL' 
		and arch_dlytrn.trndte > = getdate () - 182 
		and arch_dlytrn.prtnum = prtmst.prtnum) as [26 Wks Repln], 
	history.NJUseable as [NJ QOH], history.DueNJ as NJDue, 
	history.NVUseable as [NV QOH], history.DueNV as NVDue 
from njsql.wmsnj.dbo.prtmst prtmst, 
	pitems, njsql.wmsnj.dbo.ftpmst ftpmst, history 
where pitems.status <> 'N1'
and prtmst.vc_edpnumber = pitems.edpno 
and prtmst.prtnum = ftpmst.ftpcod 
and prtmst.vc_edpnumber = history.edpno
Next
Reply
Map
View

Click here to load this message in the networking platform