我正在为看起来非常简单的事情而苦苦挣扎,但我没有找到任何解决方案:
- 我有一个名为Hotels的表,其中的第一列是 = [hotels_id] [int]
- 我有取决于 hotels_id值的存储过程
现在在存储过程中,我只输入了一个值 (1) 作为示例,假设我有 50 行。
有什么方法可以将表中的所有行作为参数传递给 SP 吗?我的意思是一个一个。
ALTER PROCEDURE [dbo].[spAvailableRooms]
AS
BEGIN
-- Derived tables
;with
DatesTable as
(SELECT top (100) PERCENT Dates.dates_id as Id, Dates.dates_date as Date FROM Dates order by Dates.dates_id),
AvaliablePerHotel as
(SELECT top (100)percent Available_since AS Since, Available_value AS Value, Available_hotel as Hotel
FROM Available_rooms
where Available_hotel =1 --(HERE I NEED THE VALUES FROM TABLE)
ORDER BY Available_hotel, Available_since),
AllDays as
(Select top (100)percent Id, Date, Value as Rooms, iif(value is null, '0' ,'1') as New, Hotel
From DatesTable left JOIN AvaliablePerHotel ON Id = Since
order by id),
AvailableGroups as
(Select top (100)percent Hotel, Id, Date, Rooms, (sum(isnull(cast(new as float),0))over(order by id)) as RowGroup
From AllDays
order by id)
--
-- Query itself
Select Id, Date, iif(Rooms is null,(first_value(rooms) over (partition by RowGroup order by Id)) , Rooms) as AvailableRooms,
iif(Hotel is null,(first_value(Hotel) over (partition by RowGroup order by Id)) , Hotel) as Hotel
From AvailableGroups
order by id
END