>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 > >Use JOINS, do not use INLINE Field SELECTs but use derived tables and join them.
Select prtmst.prtnum as SKU, pitems.descr, pitems.status, prtmst.prtfam as family /* Comments begin, (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] Comments END*/, history.NJUseable as [NJ QOH], history.DueNJ as NJDue, history.NVUseable as [NV QOH], history.DueNV as NVDue from njsql.wmsnj.dbo.prtmst prtmst INNER JOIN pitems ON prtmst.vc_edpnumber = pitems.edpno INNER JOIN njsql.wmsnj.dbo.ftpmst ftpmst ON prtmst.prtnum = ftpmst.ftpcod INNER JOIN history ON prtmst.vc_edpnumber = history.edpno where pitems.status <> 'N1'If that runs faster then try to remove that INLINE SELECTS one by one untill you get the desired result.