I am trying to create a rentals website. There is provision to input the start date and enddate and I have to fetch records from SQL Server matching the criteria. There is a table called Bookings which stores start date and end date of Apartment bookings. In order to display Apartment records with no corresponding booking in the given time range, how can I proceed with the JavaScript function?
I have something like this right now. The select query seems to be missing something.
function searchDB() {
var start = document.getElementById("start").value;
var end = document.getElementById("end").value;
Select * from Apartments where Id NOT IN (SELECT ApartmentId from Bookings where start >= StartDate and end <= EndDate);
}
You need have a REST API which will connect to the SQL SERVER database fetches the data, The REST API end point should be invoked from Frontend javascript code using AJAX or Fetch API.