Solved

SQL Server 2008 - Improve Select Statement

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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

757 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

17 Experts available now in Live!

Get 1:1 Help Now