How to check if a room is available?

0

I have a database with 6 tables T_cliente , T_hotel , T_reserva , T_tarcre , T_tarifa and T_tiphab .

Here is the UML diagram. What I do not know how to do, is to check if the room is available or not.

Tabla T_Reserva

fechaLlegada: Date
numNoches: integer
numAdultos: integer
numMenDos: integer
numMenDosDoce: integer
TarjetaCrédito
Cliente
TipoHabitación
Tarifa
Reserva
Hotel
localizador: String
observaciones: String
precio: Double
régimen: String
codCliente: String
codHotel: String
tipoHab: String
Clave primaria: localizador
Clave foránea hacia T_Cliente codCliente
Clave foránea hacia T_Hotel codHotel
Clave foránea hacia T_TipHab tipoHab, codHotel
Clave foránea hacia T_Tarifa fechaLlegada, regimen, tipoHab, codHotel
Como clave primaria alternativa tenemos, codigoHotel, codigoCliente,
FechaLlegada, pero de esta manera sólo puede haber un reserva para un cliente en
una fecha determinada.

Tabla T_Cliente

codCliente: String
nombre: String
apellido: String
dirección: String
provincia: String
país: String
código postal: String
teléfono: String
móvil: String
email: String
Clave primaria: codCliente
Tabla T_TarCre
número: String
caducidad: String
tipo: String
codCliente: String
Clave primaria: número
Clave foránea hacia T_Cliente codCliente

Tabla T_Hotel

codigoHotel: String
Nombre: String
fechaMaxEntrada: Date
numMaxNoches : integer
Clave primaria: codHotel 



Tabla T_TipHab

tipo: String
numMáxPersonas: integer
disponibilidad: integer
codHotel: String
precio: real
Clave primaria: tipo, codHotel
Clave foránea hacia T_Hotel codHotel

Tabla T_Tarifa

precioNoche: Double
fechaInicio: Date
fechaFin: Date
regimen: String
tarifa: Double
codHotel: String
tipoHab: String
Clave primaria: fechaInicio, regimen, tipoHab, codHotel,
Clave foránea hacia T_TipHab tipoHab, codHotel 
    
asked by TOMAS 12.12.2017 в 17:42
source

1 answer

0

What I would do is from the entry date add the reserved days, so you will have the date of entry and date of departure. So when you do your comparison query you will use these dates to assess whether it is busy or not.

declare @Vfechaentrada date, @Vfechasalida date

declare @reservaciones table (
habitacion int,
fechaentrada date,
fechasalida date
)

select @Vfechaentrada=getdate() , @Vfechasalida=DATEADD (day , 4 , GETDATE() ) 

insert into @reservaciones
(habitacion,fechaentrada,fechasalida)
select 101,@Vfechaentrada,@Vfechasalida

--intentar reservar el 14 de diciembre

declare @fecha   date='14/12/2017'

select COUNT(1) as libre from @reservaciones where @fecha between  @Vfechaentrada and @Vfechasalida

It's an idea, you just have to debug it.

    
answered by 12.12.2017 в 17:54