W
WB
I have the following Access 2000 query that runs so slow I can't even wait
until finishes. (over 5 minutes so far). When I run the code in SQL Query
Analyzer it doesn't take but 1 second. I know there are differences between
what Access can handle and SQL Server, but there has to be something I can
do to make the Access query run faster. Any suggestions?
WB
Access query
SELECT a1.Id, a1.StoreId, a1.StylistId, a1.CustomerId, a1.AptDate,
a1.CreatedDate, a1.AptStatusId
FROM tblAppointment AS a1
WHERE (((a1.AptDate) Between CLng(CDate([Enter Start Date])) And
CLng(CDate([Enter End Date]))) AND ((a1.AptStatusId)=3) AND ((Exists (SELECT
*
FROM tblAppointment a2
WHERE a2.AptDate > a1.AptDate AND
a2.CustomerId = a1.CustomerId AND
a2.AptStatusId = 1 AND
a2.CreatedDate < cdate(a1.Aptdate +
1)))<>False));
SQL Query
DECLARE @startDate AS DATETIME
DECLARE @endDate AS DATETIME
SET @startDate = '01/01/2010'
SET @endDate = '01/15/2010'
SELECT a1.Id, a1.StoreId, a1.StylistId, a1.CustomerId, a1.AptDate,
cast(a1.AptDate - 2 AS DATETIME) AS 'ApptDATE', a1.CreatedDate,
a1.AptStatusId
FROM tblAppointment AS a1
WHERE a1.AptDate BETWEEN CAST(CAST(CONVERT(char(8), @startDate, 112) AS
DATETIME) AS NUMERIC) + 2 AND
CAST(CAST(CONVERT(char(8), @endDate, 112) AS
DATETIME) AS NUMERIC) + 2 AND
a1.AptStatusId = 3 AND
EXISTS (SELECT *
FROM tblAppointment a2
WHERE a2.AptDate > a1.AptDate AND
a2.CustomerId = a1.CustomerId AND
a2.AptStatusId = 1 AND
a2.CreatedDate < CAST((a1.AptDate - 1) AS DATETIME))
until finishes. (over 5 minutes so far). When I run the code in SQL Query
Analyzer it doesn't take but 1 second. I know there are differences between
what Access can handle and SQL Server, but there has to be something I can
do to make the Access query run faster. Any suggestions?
WB
Access query
SELECT a1.Id, a1.StoreId, a1.StylistId, a1.CustomerId, a1.AptDate,
a1.CreatedDate, a1.AptStatusId
FROM tblAppointment AS a1
WHERE (((a1.AptDate) Between CLng(CDate([Enter Start Date])) And
CLng(CDate([Enter End Date]))) AND ((a1.AptStatusId)=3) AND ((Exists (SELECT
*
FROM tblAppointment a2
WHERE a2.AptDate > a1.AptDate AND
a2.CustomerId = a1.CustomerId AND
a2.AptStatusId = 1 AND
a2.CreatedDate < cdate(a1.Aptdate +
1)))<>False));
SQL Query
DECLARE @startDate AS DATETIME
DECLARE @endDate AS DATETIME
SET @startDate = '01/01/2010'
SET @endDate = '01/15/2010'
SELECT a1.Id, a1.StoreId, a1.StylistId, a1.CustomerId, a1.AptDate,
cast(a1.AptDate - 2 AS DATETIME) AS 'ApptDATE', a1.CreatedDate,
a1.AptStatusId
FROM tblAppointment AS a1
WHERE a1.AptDate BETWEEN CAST(CAST(CONVERT(char(8), @startDate, 112) AS
DATETIME) AS NUMERIC) + 2 AND
CAST(CAST(CONVERT(char(8), @endDate, 112) AS
DATETIME) AS NUMERIC) + 2 AND
a1.AptStatusId = 3 AND
EXISTS (SELECT *
FROM tblAppointment a2
WHERE a2.AptDate > a1.AptDate AND
a2.CustomerId = a1.CustomerId AND
a2.AptStatusId = 1 AND
a2.CreatedDate < CAST((a1.AptDate - 1) AS DATETIME))