Solved

SQL Server 2008 - Improve Select Statement

Posted on 2014-02-04
2
412 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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Get Duration of last Status Update 4 31
Help with Sorting Full Text results 2 14
How to use Full Text CONTAINS with Case in SQL 6 20
MSDN Licensing query 5 55
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
I have a large data set and a SSIS package. How can I load this file in multi threading?
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.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

867 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

22 Experts available now in Live!

Get 1:1 Help Now