My code is below. The amount of data in my query changes and I'm having a hard time make it so the code can allow for the changes in the data. Right now it is all hard coded. The code is very simple and I'm learning slowly.
Code:
Dim strCon
Dim SQLArray
theDate = date()
newDate = DateAdd("D", -1, theDate)
'Connect to Oracle Database
strCon = "Data Source=servername:port/service;password=password;User ID=userid;Provider=OraOLEDB.Oracle.1;Persist Security Info=True;"
Dim oCon: Set oCon = WScript.CreateObject("ADODB.Connection")
Dim oRs: Set oRs = WScript.CreateObject("ADODB.Recordset")
oCon.Open strCon
Set oRs = oCon.Execute("select c.lead_stat_desc, b.lead_disp_desc, count(*) from lead a, lead_disp_ref b, lead_stat_ref c where a.dept_cd = 'END_OF_DRAW' and (a.del_stat_cd is null or a.del_stat_cd in ('CASCADE_RST','RST')) and a.lead_disp_ref_id = b.lead_disp_ref_id and a.lead_stat_ref_id = c.lead_stat_ref_id and c.dept_cd = 'END_OF_DRAW' group by c.lead_stat_desc,b.lead_disp_desc order by c.lead_stat_desc,b.lead_disp_desc,count(*)")
'oRs.Open SQLStmt
'SQLArray = oRs.GetRows(,,"COUNT(*)")
SQLArray = oRs.GetRows(,,Array(CStr("LEAD_STAT_DESC"),CStr("LEAD_DISP_DESC"),CStr("COUNT(*)")))
'oRs.Close
'Begin writing to variables
strResults = "<TABLE BORDER=2 CELLPADDING=2 CELLSPACING=2 WIDTH=500><TR><TD WIDTH=300>" & fixStrLen("LEAD_STAT_DESC",20) & "</TD><TD WIDTH=600>" & fixStrLen("LEAD_DISP_DESC",30) & "</TD>" & "<TD WIDTH=100>" & fixStrLen("COUNT(*)",10) & "</TD></TR>"
strResults2 = strResults & "<TR><TD WIDTH=300>" & fixStrLen(SQLArray(0,0), 20) & "</TD><TD WIDTH=500>" & fixStrLen(SQLArray(1,0), 30) & "</TD><TD WIDTH=100><center>" & fixStrLen(SQLArray(2,0), 10) & "</center></TD></TR>"
strResults3 = strResults2 & "<TR><TD WIDTH=300>" & fixStrLen(SQLArray(0,1), 20) & "</TD><TD WIDTH=500>" & fixStrLen(SQLArray(1,1), 30) & "</TD><TD WIDTH=100><center>" & fixStrLen(SQLArray(2,1), 10) & "</center></TD></TR>"
strResults4 = strResults3 & "<TR><TD WIDTH=300>" & fixStrLen(SQLArray(0,2), 20) & "</TD><TD WIDTH=500>" & fixStrLen(SQLArray(1,2), 30) & "</TD><TD WIDTH=100><center>" & fixStrLen(SQLArray(2,2), 10) & "</center></TD></TR>"
strResults5 = strResults4 & "<TR><TD WIDTH=300>" & fixStrLen(SQLArray(0,3), 20) & "</TD><TD WIDTH=500>" & fixStrLen(SQLArray(1,3), 30) & "</TD><TD WIDTH=100><center>" & fixStrLen(SQLArray(2,3), 10) & "</center></TD></TR>"
strResults6 = strResults5 & "<TR><TD WIDTH=300>" & fixStrLen(SQLArray(0,4), 20) & "</TD><TD WIDTH=500>" & fixStrLen(SQLArray(1,4), 30) & "</TD><TD WIDTH=100><center>" & fixStrLen(SQLArray(2,4), 10) & "</center></TD></TR>"
strResults7 = strResults6 & "<TR><TD WIDTH=300>" & fixStrLen(SQLArray(0,5), 20) & "</TD><TD WIDTH=500>" & fixStrLen(SQLArray(1,5), 30) & "</TD><TD WIDTH=100><center>" & fixStrLen(SQLArray(2,5), 10) & "</center></TD></TR>"
strResults8 = strResults7 & "<TR><TD WIDTH=300>" & fixStrLen(SQLArray(0,6), 20) & "</TD><TD WIDTH=500>" & fixStrLen(SQLArray(1,6), 30) & "</TD><TD WIDTH=100><center>" & fixStrLen(SQLArray(2,6), 10) & "</center></TD></TR></TABLE>"
oCon.Close
Set oRs = Nothing
Set oCon = Nothing
'send the email
sendemail "blah@blah.com", "blahblah@blah.com", "EOD Status/Disposition Report for " & date, strResults8
'Format Output
function fixStrLen(strValue, intLength)
fixStrLen = left(strValue & space(intLength), intLength)
end function
Function Lpad (inputStr, padChar, lengthStr)
Lpad = string(lengthStr - Len(inputStr),padChar) & inputStr
End Function
'Send email notification function
function sendEmail (strTo, strFrom, strSubject, strBody)
set objEmail = CreateObject("CDO.Message")
objEmail.From = strFrom
objEmail.To = strTo
objEmail.Subject = strSubject
objEmail.HTMLBody = strBody
objEmail.Configuration.Fields.Item ("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendusing")[/URL] = 2
objEmail.Configuration.Fields.Item ("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserver")[/URL] = "servername"
objEmail.Configuration.Fields.Item ("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserverport")[/URL] = 25
objEmail.Configuration.Fields.Update
objEmail.Send
end function