Hi. I'm having a problem with finding all results between two dates. Below is the code I'm currently using, which isn't doing exactly what I need it to do. For example, if a search is done for all entries for January 1-March 15, I get the total results for only Jan. 1-15 and March 1-15.
SELECT COUNT(ID) AS TotalLogs, SUM(QuoteValue) AS QuoteValueTotal, SUM(OrderValue) AS OrderValueTotal
FROM Intranet2.dbo.QLConversions
WHERE (YEAR(DateStarted) = #form.Year#) AND
(MONTH(DateStarted) BETWEEN #form.Month1# AND #form.Month2#) AND (DAY(DateStarted) BETWEEN #form.Day1# AND #form.Day2#)
I tried the following code next:
SELECT COUNT(ID) AS TotalLogs, SUM(QuoteValue) AS QuoteValueTotal, SUM(OrderValue) AS OrderValueTotal
FROM Intranet2.dbo.QLConversions
WHERE DateStarted Between
(select DateStarted
from Intranet2.dbo.QLConversions
WHERE (YEAR(DateStarted) = #form.Year#) AND
(MONTH(DateStarted) = #form.Month1#) AND
(DAY(DateStarted) = #form.Day1#))
AND
(select DateStarted
from Intranet2.dbo.QLConversions
WHERE (YEAR(DateStarted) = #form.Year#) AND
(MONTH(DateStarted) = #form.Month2#) AND
(DAY(DateStarted) = #form.Day2#))
But I get the following error if I use the above code:
"Only one expression can be specified in the select list when the subquery is not introduced with EXISTS."
Can someone help me out?
Thanks,
Kim
SELECT COUNT(ID) AS TotalLogs, SUM(QuoteValue) AS QuoteValueTotal, SUM(OrderValue) AS OrderValueTotal
FROM Intranet2.dbo.QLConversions
WHERE (YEAR(DateStarted) = #form.Year#) AND
(MONTH(DateStarted) BETWEEN #form.Month1# AND #form.Month2#) AND (DAY(DateStarted) BETWEEN #form.Day1# AND #form.Day2#)
I tried the following code next:
SELECT COUNT(ID) AS TotalLogs, SUM(QuoteValue) AS QuoteValueTotal, SUM(OrderValue) AS OrderValueTotal
FROM Intranet2.dbo.QLConversions
WHERE DateStarted Between
(select DateStarted
from Intranet2.dbo.QLConversions
WHERE (YEAR(DateStarted) = #form.Year#) AND
(MONTH(DateStarted) = #form.Month1#) AND
(DAY(DateStarted) = #form.Day1#))
AND
(select DateStarted
from Intranet2.dbo.QLConversions
WHERE (YEAR(DateStarted) = #form.Year#) AND
(MONTH(DateStarted) = #form.Month2#) AND
(DAY(DateStarted) = #form.Day2#))
But I get the following error if I use the above code:
"Only one expression can be specified in the select list when the subquery is not introduced with EXISTS."
Can someone help me out?
Thanks,
Kim