[英]how to apply sql query with a range of dates on crystal report
I have to retrieve of how many an employee attend to work between a range of two date. 我必须检索两个日期之间有多少员工参加工作。 I managed to get the query like this 我设法得到这样的查询
ex date range : 2012-02-03
to 2012-03-03
不适用日期范围: 2012-02-03
至2012-03-03
SELECT A.EmployeeD, A.EmployeeName, ISNULL(SUM(CASE WHEN a.AttendanceDate BETWEEN '2012-02-03' AND '2012-03-03' THEN 1 ELSE 0 END), 0) AS AttendCount
FROM (SELECT EmployeeID, EmployeeName, AttendanceDate
FROM dbo.tblAttendance
GROUP BY EMPLOYEEID, EmployeeName, AttendanceDate
) AS A
GROUP BY EMPLOYEEID, EmployeeName
but how do I use that so I can show it on Crystal Report (on C#) ? 但是如何使用它,以便可以在Crystal Report(在C#上)上显示它? I mean, I want user to be able to change the date range inside the program. 我的意思是,我希望用户能够在程序内更改日期范围。
I usually use select expert
feature for such thing but I don't think that will work for this, as far I as I know... Can anyone help me? 就我所知,我通常会使用select expert
功能,但据我所知,我认为这不行。有人可以帮助我吗? thanks in advance :) 提前致谢 :)
You can offload the counting to CR... 您可以将计数卸载到CR ...
{tblAttendance.AttendanceDate} in {?StartDate} to {?EndDate}
. 在您的选择公式中, {tblAttendance.AttendanceDate} in {?StartDate} to {?EndDate}
添加类似{tblAttendance.AttendanceDate} in {?StartDate} to {?EndDate}
的行。 At this point you have all the data you want, it's just a matter of displaying and summarizing. 至此,您已经拥有了所有想要的数据,这只是显示和汇总的问题。 distinctcount({tblAttendance.AttendanceDate},{tblAttendance.EmployeeID})
in the GroupHeader or GroupFooter. 按{tblAttendance.EmployeeID} distinctcount({tblAttendance.AttendanceDate},{tblAttendance.EmployeeID})
在GroupHeader或GroupFooter中放置一个非重复计数的摘要distinctcount({tblAttendance.AttendanceDate},{tblAttendance.EmployeeID})
。 This just means do a distinctcount() of attendance dates grouped by employee. 这只是意味着要按员工分组的出勤日期进行一个countcount()。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.