Solved

SQL Server 2008 - Improve Select Statement

Posted on 2014-02-04
2
428 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
[X]
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
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

729 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