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

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

4 answers

Check out SQL World on Planet Source Code:

http://www.pscode.com/vb/default.asp?lngWId=5

It should give you some ideas

2006-07-11 05:43:05 · answer #1 · answered by Richard H 7 · 0 0

For the first one you can actually set the day when the week starts. But it would be also possible using DayOfWeek Function
The second one is easy, Just say
Select WORKDAY from


Where JOBNO = xxx Order by WORKDAY
Then offcourse the first Workday would be the Startdate and the Last Workday would be the Enddate
Or You say
Select MIN(WORKDAY) as Startdate, Max(WORKDAY) as Enddate from
where JOBNO = xxx

Then you have two columns telling you the start- and the enddate

Helmut

2006-07-11 13:27:24 · answer #2 · answered by hswes 2 · 0 0

what sort of data is in the fields now that could be matched to a date? If WE and WORKDAY are both integers it will be difficult at best since there is no way to map it to a month/year.

if you can map WE to a date, you should be able to do something along the lines of "WE - (5-workday) days"

2006-07-11 12:49:06 · answer #3 · answered by John J 6 · 0 0

try htmlgoodies.com. You will find lots of help there

2006-07-11 12:43:05 · answer #4 · answered by Auntiem115 6 · 0 0

fedest.com, questions and answers