Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Help needed with C# / SQL appointment scheduler

Posted on 2007-03-18
4
Medium Priority
?
1,630 Views
Last Modified: 2008-03-06
I'm trying to figure out a simple and efficient way to build part of an appointment scheduler.  Basically, I have a SQL table with start and end times by date (the start and end times when a hairdresser is on the clock), and another table with existing scheduled appointments (includes time and date).   What I need to do is create a list of available times in half hour increments to display in a datagrid, but I'm not sure where to start.  Any ideas?  This is a modification of an existing application, so I have limited ability to make changes to the existing tables, but I can add new tables and stored procedures.

Thanks-
Ethan
0
Comment
Question by:esw074
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 30

Expert Comment

by:nmcdermaid
ID: 18746927
There are a few ways to do it. This is how I would do it;

1. Create a table which has a record for each 'timeslot'.

For example if you are open from 9 to 5 with 15 minute timeslots, that means 32 records.
The table has three fields:

StartDatetime (SMALLDATETIME)
EndDatetime (SMALLDATETIME)
Label (VARCHAR(20))

You populate this with all the timeslots.


Then you can create a view which joins this table (a 'timeslot' table) and your other two tables to return the data you want.

Post the existing table structure and I can help further.


0
 
LVL 8

Author Comment

by:esw074
ID: 18748137
Cool.  Ok, so let's say that the timeslot table you've proposed contains 32 timeslots beginning at 9 and ending at 5 using the fields above.

The appointments table contains existing appointment start and end times.  Let's say that for today, March 19, it contains two appointments - one from 10:00am-11:00am, and one from 1:00pm to 2:00pm.    We'll call the fields in the appointment table apptStartDate, apptStartTime and apptEndTime.

What I want to display is a list of available appointment times for March 19, meaning all of the appointment times in the timeslot table that are not already booked (every timeslot except 10am-11am and 1pm-2pm).  What do you think?  

0
 
LVL 30

Accepted Solution

by:
nmcdermaid earned 2000 total points
ID: 18754953
Basically this shows the entire calendar:


SELECT T.TimeslotLabel, ISNULL(A.AppointmentName,'No Appointment') As Appointment
FROM tblTimeslots T
LEFT OUTER JOIN
tblAppointments A
ON T.StartDateTime >= A.apptStartDate
AND T.EndDateTime <= A.apptEndDate


Then you can filter that to show just free times:

SELECT T.TimeslotLabel
FROM tblTimeslots T
LEFT OUTER JOIN
tblAppointments A
ON T.StartDateTime >= A.apptStartDate
AND T.EndDateTime <= A.apptEndDate
WHERE A.AppointmentName IS NULL
0
 
LVL 8

Author Comment

by:esw074
ID: 18781534
Sorry it took so long to confirm.  This is great, thanks!
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

671 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question