我正在尝试计算今天任何一方2天的假日预订(B.ID)。
它有效但我的结果是分开的,因为我必须介绍结束日期 假期也是如此,每个开始日期都有所不同(假期有不同的持续时间)。
将我的罪名分开。我需要的是每个日期的一个计数。有办法解决这个问题吗?我有点想从组中排除vwReturnDate但必须把它放在那里,因为我在我的计数中使用它。
在英语中我想要 - 对于每个[日期]计数[B.id]的数量,其中[B.Depart]< = [date]和[vwReturnDate]> [日期]
DECLARE @startDate DATE
DECLARE @endDate DATE
SET @startDate = Getdate()-2
SET @endDate = Getdate()+2;
WITH dates(Date) AS
( SELECT @startdate as Date
UNION ALL
SELECT DATEADD(d,1,[Date])
FROM dates
WHERE DATE < @enddate )
SELECT
[Date] as 'Calendar Date',
--CONVERT(VARCHAR(10), [Date],103) AS 'Date'
-- ,CONVERT(CHAR(2), [Date], 113) AS 'Day'
-- ,CONVERT(CHAR(4), [Date], 100) AS 'Month'
-- ,CONVERT(CHAR(4), [Date], 120) AS 'Year',
Case when B.Depart <= [date] AND vwR.ReturnDate >=[date] then count (B.ID) end AS 'Number of holidays live on date'
FROM [dates]
left join Booking B on B.depart=[Date]
inner join Quote Q on Q.ID=B.QuoteID
inner join vwReturnDate vwR on vwR.ID=B.ID
Group by [date], B.depart, vwR.ReturnDate
order by [date]
OPTION (MAXRECURSION 0)
GO