Answer the question
In order to leave comments, you need to log in
Is it possible to write a function that changes the value of a table automatically depending on the time?
I am writing a website for hotel booking. I want to automatically deactivate reservations if the guest does not show up.
I store the status in the reservation table. If the term has expired, then change the status to deactive. Can this be done with sql or Asp itself? I hope I was able to explain what I want to do.
Answer the question
In order to leave comments, you need to log in
I would generally use one field for example:
create table bookings (
id int,
active_til datetame
);
Scheduler on the DBMS side, or on the app side. But it's easier and better to just fix the time until which the reservation is active and check it when polling the status.
Write down the time the room was reserved.
Then periodically (via cron, HostedService, Quartz, Hangfire, stored procedures with triggers, Task Scheduler or whatever) make a request like
UPDATE bookings WHERE status IS 'ACTIVE' AND add(reservation_date, '<тут твой срок>') > now() AND guest_visited IS FALSE SET status = 'INACTIVE';
.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question