Sub Main()
Dim sStartDate As String
Dim sConnect As String
Dim sEndDate As String
Dim Ctr As Integer
Dim recCat As New ADODB.Recordset
Dim wksResults As Worksheet
Dim fldCount As Integer
Dim iCol As Integer
Dim sSQL As String
Dim arrGroups As String
Dim strGroups As String
With Sheets("valid RAs")
arrGroups = .Range("A2", .Range("A" & Rows.Count).End(xlUp))
End With
arrGroups = Application.Transpose(arrGroups)
strGroups = "'" & Join(arrGroups, "','") & "'"
'Query for the catalogue to be queried
Unload InputForm
Load InputForm
'Set default values
InputForm.txtStartDate.Value = Format(Now(), "DD-mmm-YYYY") & " 00:00:00"
InputForm.txtEndDate.Value = Format(Now(), "DD-mmm-YYYY") & " 23:59:59"
Do
'note: userform activate event displays the drop down list
'and sets the focus to the combobox
InputForm.Show
sStartDate = InputForm.txtStartDate.Value
sEndDate = InputForm.txtEndDate.Value
'check value of bOK that was set by the buttons on the form
If Not bOK Then Exit Sub
'if an item is selected, exit the loop
If (Not sStartDate = "") And (Not sEndDate = "") Then Exit Do
'if no item selected, display a message
MsgBox "Please ensure both start and end date are selected."
Loop
'Query for the submitter
sStartDate = InputForm.txtStartDate.Value
sEndDate = InputForm.txtEndDate.Value
Unload InputForm
'Connect to Oracle
sConnect = "Provider=MSDAORA.1;Password=" & DB_PW & ";User ID=" & DB_USERID & ";" & _
"Data Source=" & DB_NAME & ";Persist Security Info=True"
connCham.Open sConnect
sSQL = " SELECT "
sSQL = sSQL & " TICKET_ID_, PROBLEM_ID, SUBMITTED_BY, ASSIGNED_TO_GROUP_, ASSIGNED_TO_INDIVIDUAL_, TEF, "
sSQL = sSQL & " DECODE (priority, "
sSQL = sSQL & " 0, 'Low', "
sSQL = sSQL & " 1, 'Medium', "
sSQL = sSQL & " 2, 'High', "
sSQL = sSQL & " 3, 'Urgent', "
sSQL = sSQL & " 4, 'Critical' "
sSQL = sSQL & " ) ""Priority"", "
sSQL = sSQL & " DECODE (case_type, "
sSQL = sSQL & " 0, 'Incident', "
sSQL = sSQL & " 1, 'Misc', "
sSQL = sSQL & " 2, 'Request' "
sSQL = sSQL & " ) ""Case Type"", "
sSQL = sSQL & " SUB_CODE, CATEGORY, SOLUTION_TEXT,"
sSQL = sSQL & " TO_DATE (TO_CHAR ( TO_DATE ('01/01/1970 00:00:00', 'MM/DD/YYYY HH24:MI:SS') "
sSQL = sSQL & " + ((arrival_time) / (60 * 60 * 24)), "
sSQL = sSQL & " 'MM/DD/YYYY HH24:MI:SS' "
sSQL = sSQL & " ), "
sSQL = sSQL & " 'MM/DD/YYYY HH24:MI:SS' "
sSQL = sSQL & " ) ""Incident Start Time"", "
sSQL = sSQL & " TO_DATE (TO_CHAR ( TO_DATE ('01/01/1970 00:00:00', 'MM/DD/YYYY HH24:MI:SS') "
sSQL = sSQL & " + ((resolved_time) / (60 * 60 * 24)), "
sSQL = sSQL & " 'MM/DD/YYYY HH24:MI:SS' "
sSQL = sSQL & " ), "
sSQL = sSQL & " 'MM/DD/YYYY HH24:MI:SS' "
sSQL = sSQL & " ) ""Incident End Time"", "
sSQL = sSQL & " root_cause, hours_to_resolve, SUMMARY, KEYWORD"
sSQL = sSQL & " FROM INCIDENT_MANAGEMENT "
sSQL = sSQL & " WHERE"
sSQL = sSQL & "(ARRIVAL_TIME between (86400 * ( to_date('" & sStartDate & "', 'dd-mon-yyyy hh24:mi:ss') - to_date('01-jan-1970', 'dd-mon-yyyy'))) "
sSQL = sSQL & " AND (86400 * ( to_date('" & sEndDate & "', 'dd-mon-yyyy hh24:mi:ss') - to_date('01-jan-1970', 'dd-mon-yyyy')))) "
sSQL = sSQL & " and ASSIGNED_TO_GROUP_ IN ('GROUP1' , 'GROUP2' , 'GROUP3' , 'GROUP4' , 'GROUP5' , 'GROUP6' ....... 'GROUP25' ) "
sSQL = sSQL & " order by "
sSQL = sSQL & " TICKET_ID_ "
sSQL = sSQL & " "
recCat.CursorLocation = adUseClient
recCat.Open sSQL, connCham, adOpenForwardOnly, adLockReadOnly
' Copy the recordset to the worksheet, starting in cell A4
Sheets("Raw-Data").Cells(2, 1).CopyFromRecordset recCat
recCat.Close
Set recCat = Nothing
Cells.Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Range("A2").Select
connCham.Close
End Sub