Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

SQL Server 2008 - Improve Select Statement

Posted on 2014-02-04
2
419 Views
Last Modified: 2014-02-04
Is there anyway to make the below SQL faster?  When I run it it takes over a minute to return results.

Select DISTINCT top 1000
	cmp.cmpname,
	ins.first, ins.last, bp.Amount,
	ccc.amount, ccc.authorization, ccc.transaction, 
	ben.description,
	ccc.updateDT
from creditCardCharge ccc
INNER JOIN insured ins ON ccc.empid = ins.empid
INNER JOIN employee emp ON ccc.empid = emp.empid
INNER JOIN company cmp ON emp.cmpid = cmp.cmpid
INNER JOIN insuredBenefit ib ON ccc.empid = ib.empid
INNER JOIN benefitPayment bp ON ib.ibid = bp.ibid
INNER JOIN benefitPaymentBatch bpb ON bp.bpbid = bpb.bpbid
INNER JOIN benefitCoverage bc ON ib.bcid = bc.bcid 
INNER JOIN benefit ben ON bc.benid = ben.benid
ORDER BY ccc.cccupdateDT DESC

Open in new window

0
Comment
Question by:CipherIS
2 Comments
 
LVL 11

Accepted Solution

by:
John_Vidmar earned 250 total points
ID: 39832546
Try to reduce how many tables are in your query, i.e., is benefitPaymentBatch needed?

Introduce a where-clause (ccc.cccupdateDT would make sense).

Ensure indexes exist on joined fields.

Update statistics so indexes are used.

Is there a data purge strategy?   Some tables can get huge.
0
 
LVL 12

Assisted Solution

by:Paul_Harris_Fusion
Paul_Harris_Fusion earned 250 total points
ID: 39832660
As John says,  benefitPaymentBatch appears to play no part in the query.

I accept you may need it,  but for diagnostics,  try removing the order by clause.
If it speeds things up,  indexing the creditCardCharge UpdateDT column might help.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

808 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