顧客販売担当者への訪問数を取得しようとしています。先月、このSQLを作成して、現在の顧客の訪問を許可しましたが、先月の合計訪問数を取得するにはApple tである必要があります
declare @FromDate date, @ToDate date
set @FromDate = '11/01/2012'
set @ToDate = '11/30/2012'
SELECT COUNT(VisitTracking.customerID) AS #VISIT
FROM VisitTracking INNER JOIN Customers
ON VisitTracking.customerID = Customers.customerID INNER JOIN Customer_Company
ON Customers.customerID = Customer_Company.customerID INNER JOIN Company
ON Customer_Company.companyID = Company.companyID
WHERE VisitTracking.DateVisited BETWEEN
DATEADD(m, datediff(DD, 0, @FromDate)-1, 0) AND
DATEADD(M, datediff(month, 0, @ToDate)-1, 0)
GO
SELECT COUNT(VisitTracking.customerID) AS #VISIT
FROM VisitTracking
WHERE VisitTracking.DateVisited BETWEEN DATEADD(m, datediff(DD, 0, @FromDate)-1, 0) AND DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,@ToDate),0))