我有两张桌子。一个具有插槽信息,另一个保存所选的插槽。
现在我正在使用的代码是
declare @RuleId int,@starttime varchar(50),@endtime varchar(50),@r int,@interval int
SELECT
@RuleId=Rules.Rule_Serno,
@starttime = Rules.from_dt
, @endtime = Rules.to_dt
,@r=Rules.room,
@interval = Service.Service_Duration
FROM Service INNER JOIN
Rules ON Service.Service_Serno = Rules.Service_Id where Service.Service_Serno=@ServiceId
--SELECT * INTO #tmp FROM d;
declare @slots int
select @slots = datediff(minute, @starttime, @endtime)/@interval
SELECT TOP (@slots) N=IDENTITY(INT, 1, 1)
INTO #Numbers
FROM master.dbo.syscolumns a CROSS JOIN master.dbo.syscolumns b;
select
dateadd(minute,((n-1)*@interval),@starttime) as start,
dateadd(minute,(n*@interval),@starttime) as todate
into
#slots
from
#numbers
SELECT @room as RoomId,@Dt as 'Date',LEFT(CONVERT(VARCHAR,s.start, 108), 10) as Start,LEFT(CONVERT(VARCHAR,s.todate, 108), 10) as 'End', case when b.start IS null then '-' else 'xx' end as Status
FROM [#slots] AS s left JOIN
booking AS b ON s.start = b.start AND s.todate = b.todate and b.Dt=@Dt and b.Service_Id=@ServiceId and b.Room_Id=@room
drop table #numbers, #slots
问题是代码仅在插槽正好是表中描述的分钟时才有效。例如,如果插槽是60分钟,例如:如果我预订,如果我手动预订7:00到7:30它仍然显示7:00-8:00的空位。如果在保留插槽旁边手动完成,我需要在插槽之间显示任何内容。