Hi Guys,
I am a real beginner and I need to extract some information from the oracle database using a vb script and then extract to excel. What I want to do is run a SQL statement to locate all the projects and then using another SQL statement to find out the last login date to the project. and extract that to a CSV or XLS format. Please if anyone can help me out?
I have a sample below:
Dim strConnect
Dim adoConnection
Dim adoRecordset
Dim strSQL
Dim strResults
Dim rs As Recordset
strSQL = "SELECT SELECT DOMAIN_NAME, PROJECT_NAME, DB_NAME, PHYSICAL_DIRECTORY FROM QCSITEADMIN_DB.PROJECTS;
Set com = tdc.Command
com.CommandText = "SELECT MAX(START_TIME) FROM QCSITEADMIN_DB.SESSIONS_HI
STORY where PROJECT_NAME = 'strSQL' com.Execute
For i = 0 To rs.RecordCount 'note: Recordset count start from 0!
If rs.EOR = False Then
rs.Next
End If
Next
Set adoConnection = CreateObject("ADODB.Connec
tion")
strConnect ="Driver={Microsoft ODBC for Oracle}; " & _
"CONNECTSTRING=(DESCRIPTIO
N=" & _
"(ADDRESS=(PROTOCOL=TCP)" & _
"(HOST=10.21.42.218)(PORT=
1521))" & _
"(CONNECT_DATA=(SERVICE_NA
ME=TCR_SA3
KNX10DB)))
; uid=TD_ADMIN_RO;pwd=TD_ADM
IN_RO;"
adoConnection.Open strConnect
Set adoRecordset = CreateObject("ADODB.Record
set")
adoRecordset.ActiveConnect
ion = adoConnection
adoRecordset.Source = strSQL
adoRecordset.Open
Do Until adoRecordset.EOF
strResults = adoRecordset.Fields(0).Val
ue
msgbox strResults
adoRecordset.MoveNext
Loop
adoRecordset.Close
adoConnection.Close
Const xlShiftDown = -4121
'The TSV file to be converted
strInput = "c:\temp.txt"
'The Excel file to be created
strOutput = "c:\temp.xls"
'The column headings
arrColumns = array("Project Name","Date of Last QC login to Project","NAS total space of *.bmp files","Latest modified date of *.bmp files")
Set objExcel = CreateObject("Excel.Applic
ation")
objExcel.DisplayAlerts = FALSE
objExcel.Visible = FALSE
Set objWorkbook = objExcel.Workbooks.Open(st
rInput)
Set objWorksheet = objWorkbook.Worksheets(1)
intRow = objExcel.ActiveCell.Row
intColumn = objExcel.ActiveCell.Column
Set objRange = objWorksheet.Cells(intRow,
intColumn).EntireRow
objRange.Insert(xlShiftDow
n)
For Each strColumn in arrColumns
objExcel.Cells(1, intColumn).Value = strColumn
intColumn = intColumn + 1
Next
objExcel.ActiveWorkbook.Sa
veAs strOutput, 1
objExcel.ActiveWorkbook.Cl
ose
objExcel.Application.Quit
Start Free Trial