如何从followind数据库中找到avilabilty的房间

时间:2012-02-26 17:31:25

标签: visual-studio-2008

房间预订表

CREATE TABLE [dbo].[Rooms]
(    
    [room_no] [varchar](5) NOT NULL,
    [cust_id] [varchar](5)  NOT NULL,
    [check_in_date] [datetime] NOT NULL,
    [check_out_date] [datetime] NOT NULL,
    [no_of_rooms] [int] NOT NULL,
    [no_of_members] [int] NOT NULL,
    [room_type] [varchar](15) NOT NULL,
    [room_status] [varchar](50)  NOT NULL,
)

1 个答案:

答案 0 :(得分:0)

查询:

declare @dateforbooking datetime
declare @room_no varchar

set @dateforbooking = '2012-02-26 11:00'
set @room_no = 1

select 
    * 
from rooms 
where 
    room_no = @room_no
    and @dateforbooking between check_in_date and check_out_date

@room_no var表示您之后的房间号,@ dateforbooking是您希望预订房间的日期时间,如果房间已经预订,查询将返回预订的行,如果在那段时间内没有预订房间,结果将是空的。