Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 171
  • Last Modified:

Expression times out when running query

I am trying to get the maximum date for each record.  There are numerous records for each NDC and I need to get the NDC record which has the maximum time stamp for each different NDC how can I do this without the expression timeing out.

thanks
SELECT     r.NPT_PRICEx, r.NDC, r.NPT_DATEC
FROM         RNP2 r INNER JOIN
                          (SELECT     MAX(npt_datec) AS maxbbdc, NDC
                            FROM          rnp2
                            GROUP BY NDC) a ON r.NDC = a.NDC AND r.NPT_DATEC = a.maxbbdc
WHERE     (r.NPT_TYPE = '01')

Open in new window

0
running32
Asked:
running32
  • 2
2 Solutions
 
BrandonGalderisiCommented:
do you have an index on npt_datec that covers ndc?

ance since you are filtering on r.npt_type, you should put the same criteria on the inner select between "from rnp2" and the group by.
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
do you have an index on the field NDC + NPT_DATEC ?
0
 
BrandonGalderisiCommented:
wrong use of words... should have been "and" and not "that covers"


0
 
running32Author Commented:
thank you
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now