获得上个月的总访问量

时间:2012-11-30 17:46:00

标签: c# asp.net sql

我试图获得有多少访问客户销售代表。上个月我做了这个sql让我在当前的客户访问,但我需要苹果t上个月总访问量 enter image description here

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))

2 个答案:

答案 0 :(得分:0)

mmmmm,可能是你可以使用会话礼节,,,但使用它,因为你可以发挥其优势,

类似的东西:

申请开始--->

  

Application.add( “USERCOUNT”,0);

会话开始--->

  

int UserCount = int.parse(Appplication.get(“UserCount”)。tostring());   USERCOUNT ++; Application.set( “USERCOUNT”,USERCOUNT);

答案 1 :(得分:0)

使用此代码

declare @FromDate date
,@ToDate date
set @FromDate = '11/01/2012'
set @ToDate = '11/30/2012'

SELECT     COUNT(VisitTracking.customerID) AS #VISIT
FROM         VisitTracking 
WHERE VisitTracking.DateVisited  BETWEEN DATEADD(m, datediff(MM, 0, @FromDate)-1, 0)  and  DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,@ToDate),0))