SELECT
VS.PartnerID,
VS.PartnerCode,
COUNT(DISTINCT VS.VisitorSessionID) 'Clicks',
COUNT(A.ApplicationID) 'Applications',
SUM(A.Revenue) 'Revenue'
FROM VisitorSessions AS VS (NOLOCK)
LEFT JOIN VisitorApplications AS VA (NOLOCK)
ON VS.VisitorSessionID = VA.VisitorSessionID
LEFT JOIN PayableApplications AS A (NOLOCK)
ON VA.ApplicationID = A.ApplicationID
WHERE VS.StartDate >= '1/1/2004' -- *** NOTICE THIS
AND VS.StartDate < '1/2/2004' -- *** NOTICE THIS
GROUP BY VS.PartnerID, VS.PartnerCode
My problems began when I though I'd make my life simpler by replacing the
"hard-coded" dates in the WHERE clause with variable dates, like this:
DECLARE @StartDate DATETIME
DECLARE @EndDate DATETIME
SET @StartDate = '1/1/2004'
SET @EndDate = '1/2/2004'
SELECT
VS.PartnerID,
VS.PartnerCode,
COUNT(DISTINCT VS.VisitorSessionID) 'Clicks',
COUNT(A.ApplicationID) 'Applications',
SUM(A.Revenue) 'Revenue'
FROM VisitorSessions AS VS (NOLOCK)
LEFT JOIN VisitorApplications AS VA (NOLOCK)
ON VS.VisitorSessionID = VA.VisitorSessionID
LEFT JOIN PayableApplications AS A (NOLOCK)
ON VA.ApplicationID = A.ApplicationID
WHERE VS.StartDate >= @StartDate
AND VS.StartDate < @EndDate
GROUP BY VS.PartnerID, VS.PartnerCode
All of the sudden, my query that previously took 1 or 2 seconds was now
taking 45 seconds. My tables are nothing out of the ordinary, and contain a
lot, but not unreasonable amounts of data. When using a combination of Query
Analyzer and SQL Profiler, I can definitely see that SQL Server is executing
the queries much differently, but I don't understand why...
I've since gone back to some of the 10's (if not 100's) of queries and
Stored Procedures within our database and tested to see if they suffer from
the same problem - THEY DO! With that said, you can understand that I feel
like I may be loosing a ton of performance by doing things this way.
Please let me know if you have any insight into this issue - I can defnitely
use the help!
Thanks,
Chris
--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"Christopher D. Wiederspan" <wiede...@netquote.com> wrote in message
news:OXeurqr4...@tk2msftngp13.phx.gbl...
May be this works.
Regards,
Rajesh Patel
"Christopher D. Wiederspan" <wiede...@netquote.com> wrote in message
news:OXeurqr4...@tk2msftngp13.phx.gbl...
Thanks,
Chris
"Rajesh Patel" <rdp...@hotmail.com> wrote in message
news:e9f4RHt4...@TK2MSFTNGP09.phx.gbl...
Thanks for the help!
Chris
"Aaron Bertrand [MVP]" <aa...@TRASHaspfaq.com> wrote in message
news:OHCefUs4...@TK2MSFTNGP11.phx.gbl...
--
HTH,
Vinod Kumar
MCSE, DBA, MCAD, MCSD
http://www.extremeexperts.com
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp
"Christopher D. Wiederspan" <wiede...@netquote.com> wrote in message
news:%23pMNKcv...@TK2MSFTNGP12.phx.gbl...