Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
GavinD1977
Yak Posting Veteran
83 Posts |
Posted - 2006-08-11 : 06:30:52
|
| Hi all. Have a query and i'm really not sure how to approah it.OK, I have two tables. In the first table (ABSENCE) i have three fields FROMDATE, UNTILDATE and TOTAL HOURS.These field state the start and end date of an absence. I have a second table (WORKPATTERN) in this table are stored etails of an individual workpattern.It contains two fields DATE and HOURS. It stores each individual date in a workpattern and how many hours are worked on that day.Obviously there are days missed in the work pattern (I.E. saturday, sunday and bank holidays etc).What i need to do is work out the TOTALHOURS for a particlar absence. This means i need scan the range of FROMDATE to UNTILDATE.If there is a matching date in the WORKPATTNT table i need to add the HOURS for that record to running total.Not sure if ive explained it all that well. But any advice would be smashing. Thanks people. |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-08-11 : 06:34:39
|
It will be very much clearer if you could also post the table structure, some sample data and the result that you want. KH |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-08-14 : 04:00:50
|
Begin with this and see if it is getting any clearerSELECT a.*, (SELECT SUM(wp.Hours) FROM WorkPattern wp WHERE wp.Date BETWEEN a.FROMDATE AND a.UntilDate)FROM Absence a Peter LarssonHelsingborg, Sweden |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-08-14 : 11:56:09
|
| Also if you use Reports, then you can make use of Running Total featureMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|