Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Avoid sub select to improve the performance

$
0
0

Hi Team,

Share you suggestions.

    

declare @Startdate DATETIME,
    @enddate  DATETIME,
    @subsholder NVARCHAR(260) = NULL


SELECT  @startdate StartTime,
             @enddate   EndTime,
            SUM(verificationCountTotal) verificationCountTotal,
            SUM(verificationCountFailed) verificationCountFailed,
            SUM(verificationCountSlow) verificationCountSlow,
            SUM(slowTime) slowTime,
            AVG(Availability) Availability
    FROM
    (
        SELECT  SUM(verificationCountTotal) verificationCountTotal,
                SUM(verificationCountFailed) verificationCountFailed,
                SUM(verificationCountSlow)verificationCountSlow,
                SUM(slowTime) slowTime,
                (5 * COUNT(subsholder) - SUM(DownTime)) / CAST(5 * COUNT(subsholder) AS DECIMAL) subsholder
        FROM    tbl_verfication 
        WHERE   Aggregationdate >= @Startedate
                AND Aggregationdate < @enddate 
                AND ( @subsholder IS NULL OR  subsholder =  @subsholder)
        GROUP BY AggregationDate
    ) AS Data

Thanks

Thiru


Thiru


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>