CREATE TABLE "Reservation"(
ReservationID int IDENTITY (1,1) NOT NULL,
CustomerID int NOT NULL,
RoomNo int NOT NULL,
CheckInDate date NULL,
CheckOutDate date NULL,
NoOfDays int NULL,
CONSTRAINT PK_Reservation PRIMARY KEY(ReservationID),
CONSTRAINT FK_Reservation_Customers_CustID FOREIGN KEY(CustomerID)
REFERENCES dbo.Customers(CustomerID),
CONSTRAINT FK_Reservation_Rooms_RoomNo FOREIGN KEY(RoomNo)
REFERENCES dbo.Rooms(RoomNo)
)
INSERT Reservation(CustomerID,RoomNo,CheckInDate,CheckOutDate,NoOfDays)
VALUES(1,101,'2012-01-01','2012-01-30',DATEDIFF(NoOfDays,'CheckInDate','CheckOutDate'))
有人可以告诉我如何计算“CheckInDate”和“CheckOutDate”之间的天数,然后在 NoOfDays 的插入语句中使用这个值。很难解释我希望你明白我在这里想要达到的目标。