私は適切な部屋のテーブルを持っています
DECLARE @tblSuitableRooms TABLE
(
RoomID BIGINT PRIMARY KEY NOT NULL,
StartTime DATETIME NULL,
EndTime DATETIME NULL,
RoomStartTime DATETIME NULL,
RoomEndTime DATETIME NULL,
RoomStartTimeCaretaker DATETIME NULL,
RoomEndTimeCaretaker DATETIME NULL
)
@tblPossiblyAvailable テーブルに行を挿入する必要があります
DECLARE @tblPossiblyAvailable TABLE
(
RoomID BIGINT NOT NULL,
StartTime DATETIME NOT NULL,
Processed BIT NOT NULL
)
一定の分数のギャップがあります (@AdvancedSearchInterval)。私はすでに RoomStartTimes を使用してテーブルに持っています
INSERT INTO @tblPossiblyAvailable
SELECT sr.RoomID, sr.RoomStartTime, 0
FROM @tblSuitableRooms sr
WHERE sr.RoomStartTime IS NOT NULL
ただし、特定の分数の間隔 (AdvancedSearchInterval) で RoomStartTime と RoomEndTime の間の StartTime を使用して、@tblPossivelyAvailable にさらにレコードを挿入する必要があります。これにより、1 日の空室状況を確認できます。
私が必要なのはこのようなものです
RoomID StartTime
1 2013-02-26 09:00:00
1 2013-02-26 09:30:00
1 2013-02-26 10:00:00
1 2013-02-26 10:30:00
1 2013-02 -26 11:00:00
2 2013-02-26 08:00:00 2 2013-02-26
08:30:00
2 2013-02-26 09:00:00
2 2013-02-26 09:30: 00
2 2013-02-26 10:00:00
3 2013-02-26 09:00:00
3 2013-02-26 09:30:00
と言うループのようなものが必要です
insert into @tblPossiblyAvailable
select each room from @tblSuitableRooms
and take the start time for the room,
then take the start time + 30 minutes and insert that with the RoomID,
then take the last time inserted + 30 minutes and insert that with the RoomID
then take the last time inserted + 30 minutes and insert that with the RoomID
...
助けてくれてありがとう。
エド
PS SQL Server 2000 を使用しています
このソリューションは機能しているようです。誰かがそれについてもっと良い方法を考えることができれば、私は非常に興味があります.
DECLARE @AdvancedSearchInterval tinyint
DECLARE @tblSuitableRooms TABLE
(
RoomID BIGINT PRIMARY KEY NOT NULL,
StartTime DATETIME NULL,
EndTime DATETIME NULL,
RoomStartTime DATETIME NULL,
RoomEndTime DATETIME NULL,
RoomStartTimeCaretaker DATETIME NULL,
RoomEndTimeCaretaker DATETIME NULL
)
DECLARE @tblPossiblyAvailable TABLE
(
RoomID BIGINT NOT NULL,
StartTime DATETIME NOT NULL,
Processed BIT NOT NULL
)
SET @AdvancedSearchInterval = 30
INSERT INTO @tblSuitableRooms
select 1, getdate(), getdate(), '2013-02-26 08:00:00', '2013-02-26 17:00:00', getdate(), getdate()
UNION ALL
select 2, getdate(), getdate(), '2013-02-26 10:00:00', '2013-02-26 19:00:00', getdate(), getdate()
UNION ALL
select 3, getdate(), getdate(), '2013-02-26 09:00:00', '2013-02-26 17:00:00', getdate(), getdate()
DECLARE @mins INT
SET @mins = 0
WHILE @mins < 1440
BEGIN
INSERT INTO @tblPossiblyAvailable
SELECT RoomID, DATEADD(MINUTE,@mins,RoomStartTime), 0
FROM @tblSuitableRooms
WHERE DATEADD(MINUTE,@mins,RoomStartTime) < RoomEndTime
SET @mins = @mins + @AdvancedSearchInterval
END
SELECT *
FROM @tblPossiblyAvailable
ORDER BY StartTime