English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

lets say i have a supervisor that is contracted to work from date_a to date_b (e.g. 01/01/2005 to 01/01/2010). I have just recruited and new employee which needs a supervisor. the new employee is contracted to work from date_c to date_d. A supervisor can only be assigned to an employee, if the employee's contract timeperiod falls within supervisor's contract timeperiod. How do i work this out in SQL (Microsoft SQL Server 2000)?

2006-11-06 00:14:10 · 3 answers · asked by Anonymous in Computers & Internet Programming & Design

3 answers

in other word has condition
1. employe contract start(date_c) >= supervisor contract start
(date_a)
or
date_c >= date_a
or
date_a <= date_c


2. employe contract end(date_d) <= supervisor contract end(date_b)
or
date_d <= date_b
or
date_b>= date_d


Mervin one almost correct

select * from tablename where data_a<=date_c and date_b>=date_d

2006-11-07 23:41:38 · answer #1 · answered by safrodin 3 · 0 0

Try this fragment... you'll need to massage it to fit your constraints, but....

select
case when
startdate >= {ts '2001-05-24 10:30:29.123'}
AND enddate <= {ts '2001-05-24 10:30:29.123'}
AND
startdate >= {ts '2002-05-24 10:30:29.123'}
and enddate <= {ts '2002-05-24 10:30:29.123'}

then 1 else 0 end
from supervisor

the timestamp 2001-05-24 is May 24, 2001 (for when the employee starts) and 2002-05-24 is the end date. Use whatever date you need. You may have to join on your employee table to get that date... but I am assuming you know the dates...

2006-11-06 08:45:39 · answer #2 · answered by mchenryeddie 5 · 0 0

select * from table where data_adate_d

2006-11-07 12:58:16 · answer #3 · answered by life goes on... 2 · 0 0

fedest.com, questions and answers