Query optimization

Execution plan doubts.
Query is running so long time can any one pl say how can i check am attaching my execution plan file and my function file also.
kowsika deviAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Vitor MontalvãoMSSQL Senior EngineerCommented:
If you can remove the DISTINCT from the queries then it will help to improve the performance.
kowsika deviAuthor Commented:
but i need with out duplicates victor jj.
Vitor MontalvãoMSSQL Senior EngineerCommented:
DISTINCT is not the only way to guarantee the uniqueness of the results from a query.
You can review your JOINs as most of the times, adding a new join clause will be enough to guarantee the uniqueness of the results.
Other option is to use GROUP BY. This is the example for your case:
SELECT d.PymntBatchNo,
	CONVERT(VARCHAR, d.PymntBatchDT, 103) AS PymntBatchDT,
    'Other'                               AS PdtShrtDescr
FROM   Loln_LnDisbmntPaymntDet d (nolock)
    JOIN loln_lnpayablelocation LnPL WITH (nolock) ON d.PymtLocShrtDescr = LnPL.LocShrtDescr
    JOIN LOln_ProposalEntry_h h (nolock) ON d.LnNo = h.PrpslNo
    JOIN LGen_CntrlngUnit c (nolock) ON h.UnitShrtDescr = c.UnitShrtDescr AND h.PdtShrtDescr = c.PdtShrtDescr
WHERE d.PymntBatchNo NOT IN('-1', '9', '')
    AND d.REFPymntBatchNo IS NULL 
	AND	LnPL.BankAccCode = '135570' and c.DisbmntCntrlUnit = 'LUDHO' 
    AND PrpslStat NOT IN ( 'Cancelled', 'Closed' )      
    AND PymntBatchNo LIKE Ltrim(Rtrim(397)) + '%' 
GROUP BY d.PymntBatchNo, CONVERT(VARCHAR, d.PymntBatchDT, 103)
SELECT d.PymntBatchNo,
	CONVERT(VARCHAR, d.PymntBatchDT, 103) AS PymntBatchDT,
FROM Loln_LnTaDetails_H d (nolock)
	JOIN LGen_CntrlngUnit c (nolock) ON c.UnitShrtDescr = d.UnitShrtDescr
				AND c.PdtShrtDescr = d.PdtShrtDescr
				AND c.DisbmntCntrlUnit = 'JAIPR'
WHERE d.CompShrtDescr = 'SCUF' AND d.AccCode='135570' 
	AND d.PymntBatchNo NOT IN('-1', '9', '')
    AND Isnull(d.REFPymntBatchNo, '') = ''
    AND PymntBatchNo LIKE Ltrim(Rtrim(699)) + '%'
GROUP BY d.PymntBatchNo, CONVERT(VARCHAR, d.PymntBatchDT, 103), d.PdtShrtDescr

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Vitor MontalvãoMSSQL Senior EngineerCommented:
Solution provided.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.