Hello. I have a scheduling application that ensures a task is manually added to the schedule every day. We operate the manual scheduling process every few days. I need to figure out a way to calculate the next opening in the calendar. It needs to return the first "gap" it finds as it counts from today forward....not the date that is the furthest out.
Example: If we have a task scheduled for each of the next 3 days, I need to find the gap that exists starting on day 4 and return that date. This will allow the scheduler to know how far out the schedule has been created.
ChatGPT says I should run the following SQL queries in a calculated field, but I don't believe Caspio will allow these subqueries. Does anyone have any ideas how to accomplish finding the next opening on the schedule?
SELECT
(SELECT MIN(DueDate + 1)
FROM Pin_Creation_Schedule
WHERE ServiceID = [@field:Pin_Creation_Details_ServiceID]
AND DueDate >= CAST(GETDATE() AS DATE)
AND NOT EXISTS (
SELECT 1
FROM Pin_Creation_Schedule AS innerTable
WHERE innerTable.ServiceID = [@field:Pin_Creation_Details_ServiceID]
AND innerTable.DueDate = Pin_Creation_Schedule.DueDate + 1
)
) AS NextGapDate
FROM Pin_Creation_Schedule
WHERE ServiceID = [@field:Pin_Creation_Details_ServiceID]
AND DueDate >= CAST(GETDATE() AS DATE)
You can post now and register later.
If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.
Question
MacCaspio
Hello. I have a scheduling application that ensures a task is manually added to the schedule every day. We operate the manual scheduling process every few days. I need to figure out a way to calculate the next opening in the calendar. It needs to return the first "gap" it finds as it counts from today forward....not the date that is the furthest out.
Example: If we have a task scheduled for each of the next 3 days, I need to find the gap that exists starting on day 4 and return that date. This will allow the scheduler to know how far out the schedule has been created.
ChatGPT says I should run the following SQL queries in a calculated field, but I don't believe Caspio will allow these subqueries. Does anyone have any ideas how to accomplish finding the next opening on the schedule?
SELECT
(SELECT MIN(DueDate + 1)
FROM Pin_Creation_Schedule
WHERE ServiceID = [@field:Pin_Creation_Details_ServiceID]
AND DueDate >= CAST(GETDATE() AS DATE)
AND NOT EXISTS (
SELECT 1
FROM Pin_Creation_Schedule AS innerTable
WHERE innerTable.ServiceID = [@field:Pin_Creation_Details_ServiceID]
AND innerTable.DueDate = Pin_Creation_Schedule.DueDate + 1
)
) AS NextGapDate
FROM Pin_Creation_Schedule
WHERE ServiceID = [@field:Pin_Creation_Details_ServiceID]
AND DueDate >= CAST(GETDATE() AS DATE)
Link to comment
Share on other sites
2 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.