Groups | Blog | Home
all groups > sql server programming > may 2006 >

sql server programming : booking db design help


sammy
5/3/2006 11:52:45 PM
Hey Guys,
I am trying to create a web app that uses an SQL db to handle employee
scheduling. I can design a table to hold the appointments with no problems
but I need to be able to search for free time for the employees.
all bookings are based on 30 minutes blocks.
So far I managed to create all tables and this is what I have concerning the
booking tables "after seeing this post on
http://www.webservertalk.com/archive289-2005-9-1206387.html due to my lack
of DB design I am having a hard time understanding the solution.

eventually I need to be able to achieve the search using similar statement
to this
select min(starttime)
from schedule
where usedflag='free'
and duration >= :desired_duration

but I am having a problem with tables structure.
would someone explain the structure posted please?
thanks in advance


sammy
5/4/2006 2:01:01 AM
Thanks for the response Uri,
what I am thinking of best way to to describe the data is like this. I will
create a table to hold sku's refering to the services to be booked the
skutable should be something like this
SKuID --PK
Description --- char
Durration -->30 minutes blocks number field where 1 = 30 and 2=60 and so on
The employee table should be like this
EmpID --->PK
Fname
Lname
location
ScheduleID -->FK
the scheduletable should be like this
SID --->PK
sundayStart ---> ie 12/06/2006 9:30 AM
SundayEnd ---> 12/06/2006 6:00 PM
MondayStart
MondayEnd
TuesdayStart
TuesdayEnd
WedStart
WedEnd
ThurStart
ThursEnd
FridayStart
FridayEnd
SaturedayStart
SatureDayEnd

what I am trying to achieve can be described best as calenday with all
employees, the workdays, starttime, endtime and the times they are available
to take calls "calls are based on 30 minutes blocks incremening by 30
minutes.
I hope that explains the issue better

[quoted text, click to view]

Uri Dimant
5/4/2006 8:29:56 AM
sammy
It ishard to suggest soemthing without seeing the actual data and some DDL
Take a look at Itzik Ben-Gan's example showing the intreval connections to
the internet and resturns the connections was made less than 5 minutes

create table tblConnection
(
StartTimeCon datetime not null,
EndTimeCon datetime not null

)

insert into tblConnection(StartTimeCon,EndTimeCon)values ('20000610
10:00','20000610 10:10')

insert into tblConnection(StartTimeCon,EndTimeCon)values ('20000610
10:20','20000610 10:22')
insert into tblConnection(StartTimeCon,EndTimeCon)values ('20000610
10:23','20000610 10:25')
insert into tblConnection(StartTimeCon,EndTimeCon)values ('20000610
10:27','20000610 10:45')

insert into tblConnection(StartTimeCon,EndTimeCon)values ('20000610
11:57','20000610 12:00')
insert into tblConnection(StartTimeCon,EndTimeCon)values ('20000610
12:01','20000610 12:04')
insert into tblConnection(StartTimeCon,EndTimeCon)values ('20000610
12:04','20000610 12:40')
select * from tblConnection

SELECT
StartTimeCon,
ISNULL(
(SELECT MIN(EndTimeCon)
FROM tblConnection AS S3
WHERE S3.StartTimeCon >= S1.StartTimeCon
AND ISNULL(
DATEDIFF(
minute,
S3.EndTimeCon,
(SELECT MIN(StartTimeCon)
FROM tblConnection AS S4
WHERE S4.StartTimeCon > S3.EndTimeCon)), 5) >= 5),
EndTimeCon) AS EndTimeCon
FROM tblConnection AS S1
WHERE ISNULL(
DATEDIFF(
minute,
(SELECT MAX(EndTimeCon)
FROM tblConnection AS S2
WHERE S2.EndTimeCon < S1.StartTimeCon),S1.StartTimeCon),5) >= 5




[quoted text, click to view]

Uri Dimant
5/4/2006 10:10:08 AM
sammy
Take a look at http://www.aspfaq.com/show.asp?id=2519



[quoted text, click to view]

AddThis Social Bookmark Button