0

我有一个存储过程,我想根据今天的日期、本周和当前月份返回仅包含记录计数的三列

SELECT count(*) as TotalCount 
FROM CalendarItem t 
LEFT JOIN company c ON t.companyID = c.companyID AND c.enabled = 1 
INNER JOIN CalendarItemType tt ON tt.CalendarItemtypeID = t.CalendarItemTypeID 
LEFT JOIN request r ON r.requestID=t.workrequestID 

where t.deleted = 0  + @where

目前我通过传递不同的参数在今天一周和一个月内执行这个 Sp 三次

@where =AND (t.startDate BETWEEN '2013-7-17' AND '2013-7-18')

和一周

@where = AND (t.startDate BETWEEN '2013-7-14 00:00:00' AND '2013-7-20')

和一个月一样

我希望我的 SP 根据 Today's Date 、 week date 和 MOnth 返回三个计数

所以知道我应该怎么做

谢谢

4

2 回答 2

1

将三个输出参数传递给存储过程,并在sp中设置其值,然后您可以轻松将其取回

于 2013-07-17T09:53:57.813 回答
1

请试试:

SELECT 
    sum(case when t.startDate BETWEEN '2013-7-17' AND '2013-7-18' then 1 else 0 end) as DayCount,
    sum(case when t.startDate BETWEEN '2013-7-14' AND '2013-7-20' then 1 else 0 end) as WeekCount,
    //month condition here
FROM CalendarItem t 
LEFT JOIN company c ON t.companyID = c.companyID AND c.enabled = 1 
INNER JOIN CalendarItemType tt ON tt.CalendarItemtypeID = t.CalendarItemTypeID 
LEFT JOIN request r ON r.requestID=t.workrequestID 

where t.deleted = 0  
于 2013-07-17T09:55:22.780 回答