0

Below is DDL for the table I want to create. However, I want the attribute 'Appointment_datetime' to be a future date and during working hours (between 8:00AM and 5:00PM). I can get the future date part with -'CHECK (Appointment_datetime >= GETDATE()) But how do I get between 8AM and 5PM ontop of this constraint?

CREATE TABLE tAppointment
(
Appointment_ID       int        NOT NULL    PRIMARY KEY,
Appointment_datetime datetime   NOT NULL,   -- CHECK CONSTRAINTS NEEDED             
Appointment_week     int        NOT NULL,
Appointment_room     varchar(5) NOT NULL,   
Vet_ID               int        NOT NULL    REFERENCES tVet(Vet_ID),
Owner_ID             int        NOT NULL    REFERENCES tOwner(Owner_ID),
Pet_ID               int        NOT NULL    REFERENCES tPet(Pet_ID)
)
4

1 に答える 1

0

追加するだけです。 を使用した方法は次のhourとおりです。

CHECK (Appointment_datetime >= GETDATE() AND
       DATEPART(HOUR, GETDATE()) NOT BETWEEN 8 AND 16
      ) 

注: 週末と休日を考慮に入れたい場合は、より難しく、おそらくユーザー定義関数が必要になります。

于 2016-03-19T14:10:03.430 に答える