Solved

Expression times out when running query

Posted on 2008-10-02
4
158 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
SQL query syntax with WHERE and '%[ABC' clause 1 30
Excel to create SQL insert 7 35
how to do this MS SQL script? 11 48
sQL pivot 9 39
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.…
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now