We have a call-out schedule which details the employee on call for any day by the hour, the table looks something like this
ID EmpID CallDate CallHr
1 55 2006-12-01 1
2 55 2006-12-01 2
3 55 2006-12-01 3
4 55 2006-12-01 4
5 55 2006-12-01 5
6 55 2006-12-01 6
7 55 2006-12-01 7
8 55 2006-12-01 8
9 55 2006-12-01 9
10 55 2006-12-01 10
11 55 2006-12-01 11
12 55 2006-12-01 12
13 55 2006-12-01 13
14 68 2006-12-01 14
15 68 2006-12-01 15
16 68 2006-12-01 16
17 55 2006-12-01 17
18 55 2006-12-01 18
19 70 2006-12-01 19
20 70 2006-12-01 20
21 70 2006-12-01 21
22 70 2006-12-01 22
23 70 2006-12-01 23
24 70 2006-12-01 24
25 70 2006-12-02 1
26 70 2006-12-02 2
27 70 2006-12-02 3
28 70 2006-12-02 4
29 70 2006-12-02 5
30 70 2006-12-02 6
What I am trying to achieve is a summarised view of start/end of call
i.e.
EmpID CallDate St Fin
55 2006-12-01 1 13
68 2006-12-01 14 16
55 2006-12-01 17 18
70 2006-12-01 19 24
70 2006-12-02 1 6
Obviously MIN and MAX aren't suitable because it is possible for the same employee to be on call at different parts of the day.
I achieved this in VB using the following code:
I have tried in vain to convert this to a stored procedure - any advice would be very much appreciated.
Thanks Mark
ID EmpID CallDate CallHr
1 55 2006-12-01 1
2 55 2006-12-01 2
3 55 2006-12-01 3
4 55 2006-12-01 4
5 55 2006-12-01 5
6 55 2006-12-01 6
7 55 2006-12-01 7
8 55 2006-12-01 8
9 55 2006-12-01 9
10 55 2006-12-01 10
11 55 2006-12-01 11
12 55 2006-12-01 12
13 55 2006-12-01 13
14 68 2006-12-01 14
15 68 2006-12-01 15
16 68 2006-12-01 16
17 55 2006-12-01 17
18 55 2006-12-01 18
19 70 2006-12-01 19
20 70 2006-12-01 20
21 70 2006-12-01 21
22 70 2006-12-01 22
23 70 2006-12-01 23
24 70 2006-12-01 24
25 70 2006-12-02 1
26 70 2006-12-02 2
27 70 2006-12-02 3
28 70 2006-12-02 4
29 70 2006-12-02 5
30 70 2006-12-02 6
What I am trying to achieve is a summarised view of start/end of call
i.e.
EmpID CallDate St Fin
55 2006-12-01 1 13
68 2006-12-01 14 16
55 2006-12-01 17 18
70 2006-12-01 19 24
70 2006-12-02 1 6
Obviously MIN and MAX aren't suitable because it is possible for the same employee to be on call at different parts of the day.
I achieved this in VB using the following code:
Code:
...
Set rst1 = New ADODB.Recordset
sql = "SELECT * FROM CallOutTbl ORDER BY 1"
With rst1
.Source = sql
Set .ActiveConnection = GCNN
.CursorType = adOpenStatic
.CursorLocation = adUseClient
.LockType = adLockOptimistic
.Open Options:=adCmdText
End With
If rst1.RecordCount = 0 Then
RotaPhase2 = 1
rst1.close
Set rst1 = Nothing
Exit Function
End If
GCNN.BeginTrans
GCNN.Execute "DELETE FROM [CallOutRotaTbl]"
GCNN.CommitTrans
Set rst = New ADODB.Recordset
With rst
.Source = "CallOutRotaTbl"
Set .ActiveConnection = GCNN
.CursorType = adOpenStatic
.CursorLocation = adUseClient
.LockType = adLockOptimistic
.Open Options:=adCmdTable
End With
rst1.MoveFirst
GCNN.BeginTrans
z = 1
Do
Sdate = rst1(1)
Emp = rst1(4)
sSeg = rst1(3)
rst.AddNew
rst(1) = Sdate
rst(2) = rst1(2)
rst(3) = rst1(3)
rst(5) = Emp
rst(6) = UserID
Do
eSeg = rst1(3)
rst1.MoveNext
If rst1.EOF = True Then Exit Do
sSeg = sSeg + 1
Loop Until Sdate <> rst1(1) Or Emp <> rst1(4) Or sSeg <> rst1(3)
rst(4) = eSeg
rst.Update
Loop Until rst1.EOF = True
GCNN.CommitTrans
I have tried in vain to convert this to a stored procedure - any advice would be very much appreciated.
Thanks Mark