Re: SQL tuning
From: Uri Dimant (urid_at_iscar.co.il)
Date: 06/14/04
- Next message: Ian Boyd: "Re: How to deal with invoice detail money amounts?"
- Previous message: Immy: "Re: sql server job"
- In reply to: Nesaar: "SQL tuning"
- Next in thread: Hugo Kornelis: "Re: SQL tuning"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 14 Jun 2004 14:10:06 +0200
Nesaar
It is hard to suggest something , so have you looked at execution plan of
the query? Does SQL Server optimizer use indexes to perfom the query?
I see you are using a variable in the query.Is it stored procedure that
accept a parameter? It might be that otpimizer uses a 'bad' execution plan
which based on preveious variable.
"Nesaar" <nbanderker@fairbairncapital.com> wrote in message
news:uvKHo4fUEHA.3988@tk2msftngp13.phx.gbl...
> Hi. Does anyone perhaps know of a way to re-write this query to perhaps
make
> it a bit faster. It used to be a single select statement but then i had to
> break it up to cater for specific exclusions. I have added indexes and so
> on. Any ideas?
>
> Thanks
> N
>
> SELECT qrt.QuarterlyClientID, qrt.ClientID, qrt.zPolicyTypeID,
> SUM(qrt.TxnAmount),
> CAST( (DATEDIFF(DAY, qrt.TxnDate, @QuarterCloseDate)) as float)/365.25
> FROM dbo.QuarterlyRunPortfolio qrp (NOLOCK) INNER JOIN
> QuarterlyRunPolicyTransaction qrt (NOLOCK)
> ON (qrp.QuarterlyClientID = qrt.QuarterlyClientID
> AND qrp.ClientID = qrt.ClientID
> AND qrp.zPolicyTypeID = qrt.zPolicyTypeID)
> INNER JOIN dbo.zFund f (NOLOCK)
> ON (qrt.zFundID = f.zFundID
> AND ISNULL(f.LoanFund, 'N') = 'N')
> WHERE qrt.SortOrder NOT IN (5,6,7,8,9)
> AND UPPER(LEFT(qrp.ClientId,1)) = 'A'
> GROUP BY qrt.QuarterlyClientID, qrt.ClientID, qrt.zPolicyTypeID, TxnDate
> HAVING SUM(qrt.TxnAmount) <> 0
> --
> UNION
> ---
> -- Process all the IF clients and exclude the dividend and the initial ut
> fee associated with that dividend distribution
> SELECT qrt.QuarterlyClientID, qrt.ClientID, qrt.zPolicyTypeID,
> SUM(qrt.TxnAmount),
> CAST( (DATEDIFF(DAY, qrt.TxnDate, @QuarterCloseDate)) as float)/365.25
> FROM dbo.QuarterlyRunPortfolio qrp (NOLOCK) INNER JOIN
> QuarterlyRunPolicyTransaction qrt (NOLOCK)
> ON (qrp.QuarterlyClientID = qrt.QuarterlyClientID
> AND qrp.ClientID = qrt.ClientID
> AND qrp.zPolicyTypeID = qrt.zPolicyTypeID)
> INNER JOIN dbo.zFund f (NOLOCK)
> ON (qrt.zFundID = f.zFundID
> AND ISNULL(f.LoanFund, 'N') = 'N')
> WHERE NOT EXISTS (SELECT * FROM
> FairbairnReporting.dbo.IFDividendDistribution ifd
> WHERE qrt.TxnDate = ifd.InvestmentDate
> AND qrt.zProductId = ifd.zProductId
> AND qrt.zFundId = ifd.zFundId
> AND qrt.PolicyId = ifd.PolicyId
> AND qrt.TxnAmount = ifd.Amount)
> AND NOT EXISTS (SELECT *
> FROM FairbairnReporting.dbo.IFInitialUnitTrustFee ifu
> INNER JOIN FairbairnReporting.dbo.IFDividendDistribution ifd1
> ON ifu.InvestmentDate = ifd1.InvestmentDate
> AND ifu.zProductId = ifd1.zProductId
> AND ifu.zFundId = ifd1.zFundId
> AND ifu.PolicyId = ifd1.PolicyId
> WHERE qrt.TxnDate = ifu.InvestmentDate
> AND qrt.zProductId = ifu.zProductId
> AND qrt.zFundId = ifu.zFundId
> AND qrt.PolicyId = ifu.PolicyId
> AND qrt.TxnAmount = ifu.Amount)
> AND UPPER(LEFT(qrp.ClientId,1)) != 'A'
> GROUP BY qrt.QuarterlyClientID, qrt.ClientID, qrt.zPolicyTypeID, TxnDate
> HAVING SUM(qrt.TxnAmount) <> 0
>
>
- Next message: Ian Boyd: "Re: How to deal with invoice detail money amounts?"
- Previous message: Immy: "Re: sql server job"
- In reply to: Nesaar: "SQL tuning"
- Next in thread: Hugo Kornelis: "Re: SQL tuning"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|