Solved

Expression times out when running query

Posted on 2008-10-02
4
160 Views
Last Modified: 2010-03-20
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
Comment
Question by:running32
  • 2
4 Comments
 
LVL 39

Accepted Solution

by:
BrandonGalderisi earned 250 total points
ID: 22627799
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
 
LVL 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 250 total points
ID: 22627805
do you have an index on the field NDC + NPT_DATEC ?
0
 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 22627858
wrong use of words... should have been "and" and not "that covers"


0
 

Author Comment

by:running32
ID: 22628272
thank you
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question