Our database records the weekending (WE) and the day (WORKDAY) our employee (EMPNO) was at the job (JOBNO). Unfortunately, our company has added a twist and starts thier workweek on Wednesdays.
I need a SQL formula that will convert WORKDAY and WE into a date. In Excel "=IF(WORKDAY<3, (WE-2+WORKDAY), (WE-9+WORKDAY))" works.
Also, I need the statement to find the MIN and MAX values in those dates to tell me when we started and finished the job (JOBNO). Any help would be appreciated. I've only been thinking about it for 90 minutes, and my head already hurts....
2006-07-11
05:37:41
·
4 answers
·
asked by
bleme
4
in
Computers & Internet
➔ Programming & Design
WE is a date. Always on Tuesday. The last WE is 07/04/2006. Thanks for all the help so far.
2006-07-11
05:57:12 ·
update #1
Thanks for all the help guys - this code seems to be working - not only does it find the first day we dtarted, but if we haven't started, it puts in the date we estimate starting.
SELECT
(CASE WHEN min(CASE when source = 'PR' then (dateadd(dd,(CASE when (0 + workday) > 2 then (0 + workday - 9) else (0 + workday - 2) end), we)) else NULL end) is null THEN eststart ELSE min(case when source = 'PR' then (dateadd(dd, (case when (0 + workday) > 2 then (0 + workday - 9) else (0 + workday - 2) end), we)) else '9999-12-31' end) END) as "startdate",
2006-07-12
05:41:16 ·
update #2