• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Urgent Query Help

 
Rishi Chopra
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ,

i am doing this application in which---
i want to check in database whether a particular record exist between timein and timeout field.

e.g suppose rishi takes lecture and his timein is 12:30 and his timeout is 14:50 this record already there in data
now when i again create a new record i want to check whether new record has rishi in between 12:30 and 14:50 and if it is there i want to abandon record creation like if the new record has timein 13:30 to 14:55 i want to abandon record creation similarly

if record 16:30 (timein) and 18 30(timeout) exist then if i try creating a record with timein 14:15 and 16:45 (timeout)[see in bold there is conflict here] ....so i want to abandon record creation .................plz tel
Plz tel me fast as i need it urgently

Rgds
Rishi Chopra
 
Mahesh Rana
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lets approach the solution.

1. Basically, you are trying to avoid any overlap between existing time range and new time range.

2. Which makes 4 possibilities where you should not be creating new records
a. old range is subset of new range
(tin_new - tin_old - tout_old - tout_new)
b. new range is subset of old range
(tin_old - tin_new - tout_new - tout_old)
c. partial overlap,
(tin_old - tin_new - tout_old - tout_new)
d. partial overlap in other way
(tin_new - tin_old - tout_new - tout_old)

3. So the pseudo-code shold look like

Don't create the record if
tin_new < tin_old && tout_old < tout_new
or
tin_old < tin_new && tount_new < tout_old
or
tin_old < tout_in && tout_old < tout_new
or
tin_new < tin_old && tout_new < tout_old
endif


(You can also solve it by considering the possibilities where you
should be creating the new record, which is much easire than the
above solution)

I leave it up to you to.
[ December 25, 2005: Message edited by: Deep Narsay ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic