7

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

4

1 に答える 1

18

これはうまくいくはずです:

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

于 2012-11-04T18:56:20.153 に答える