I'm calculating income of hiring equipments for a report. In that, hiring cost in weekend days will be plus 10% more if compare with normal days. So how can I calculate there's how many weekend days between two dates. And in report query, I can't use DECLARE also. Can someone help me to do this. Thank you so much
我正在计算报告的招聘设备收入。在这方面,如果与正常天数相比,周末天的招聘成本将增加10%。那么如何计算两个日期之间的周末天数。而在报表查询中,我也不能使用DECLARE。有人可以帮助我做到这一点。非常感谢
1 个解决方案
#1
13
This should work:
这应该工作:
DECLARE @StartDate DATETIME
DECLARE @EndDate DATETIME
SET @StartDate = '2012/11/01'
SET @EndDate = '2012/11/05'
SELECT
(DATEDIFF(wk, @StartDate, @EndDate) * 2)
+(CASE WHEN DATENAME(dw, @StartDate) = 'Sunday' THEN 1 ELSE 0 END)
+(CASE WHEN DATENAME(dw, @EndDate) = 'Saturday' THEN 1 ELSE 0 END)
http://sqlfiddle.com/#!3/d41d8/5707/0
http://sqlfiddle.com/#!3/d41d8/5707/0
#1
13
This should work:
这应该工作:
DECLARE @StartDate DATETIME
DECLARE @EndDate DATETIME
SET @StartDate = '2012/11/01'
SET @EndDate = '2012/11/05'
SELECT
(DATEDIFF(wk, @StartDate, @EndDate) * 2)
+(CASE WHEN DATENAME(dw, @StartDate) = 'Sunday' THEN 1 ELSE 0 END)
+(CASE WHEN DATENAME(dw, @EndDate) = 'Saturday' THEN 1 ELSE 0 END)
http://sqlfiddle.com/#!3/d41d8/5707/0
http://sqlfiddle.com/#!3/d41d8/5707/0