bogorman
asked on
Calculating two totals from a recordset
I am using CodeCharge Studio to develop a website.
In the BeforeShow event of a webpage, I want to count:
1. the number of records which have a particular field which has data in it
2. the number of records where this field has no data in it.
I have used this coding which displays -1 for the first.
Dim SQLEmails, SQLNoEmails, TotalEmails, TotalNoEmails, UserID, Connection
Dim myConn, myCmd, myRS
Set Connection = New clsDBConnection1
Connection.Open
UserID = Connection.ToSQL(CCGetUser ID(), ccsInteger)
Connection.Close
Set Connection = Nothing
On Error Goto 0
Set myConn = Server.CreateObject("ADODB .Connectio n")
Set myCmd = Server.CreateObject("ADODB .Command")
Set myRS = Server.CreateObject("ADODB .Recordset ")
myConn.Open("dsn=lifenet;u id=brianog ;password= boggle")
SQLEmails = "SELECT COUNT(*) FROM tblselectedschools WHERE fldUserID = " & UserID & " AND TRIM(tblselectedschools.fl dEmail) <> ''"
SQLNoEmails = "SELECT COUNT(*) FROM tblselectedschools WHERE fldUserID = " & UserID & " AND TRIM(tblselectedschools.fl dEmail) = ''"
With myCmd
.ActiveConnection = myConn
.CommandText = SQLEmails ' This should be your SQL select statement
.CommandType = 1 'adCmdText
End With
myRS.Open myCmd
TotalEmails=myRS.RecordCou nt
response.Write TotalEmails
response.end
MyConn.Close
Header.lblHeaderLeft.Value ="School email addresses"
I am sure there is an easier way of doing this. Would be grateful for anyone's help.
In the BeforeShow event of a webpage, I want to count:
1. the number of records which have a particular field which has data in it
2. the number of records where this field has no data in it.
I have used this coding which displays -1 for the first.
Dim SQLEmails, SQLNoEmails, TotalEmails, TotalNoEmails, UserID, Connection
Dim myConn, myCmd, myRS
Set Connection = New clsDBConnection1
Connection.Open
UserID = Connection.ToSQL(CCGetUser
Connection.Close
Set Connection = Nothing
On Error Goto 0
Set myConn = Server.CreateObject("ADODB
Set myCmd = Server.CreateObject("ADODB
Set myRS = Server.CreateObject("ADODB
myConn.Open("dsn=lifenet;u
SQLEmails = "SELECT COUNT(*) FROM tblselectedschools WHERE fldUserID = " & UserID & " AND TRIM(tblselectedschools.fl
SQLNoEmails = "SELECT COUNT(*) FROM tblselectedschools WHERE fldUserID = " & UserID & " AND TRIM(tblselectedschools.fl
With myCmd
.ActiveConnection = myConn
.CommandText = SQLEmails ' This should be your SQL select statement
.CommandType = 1 'adCmdText
End With
myRS.Open myCmd
TotalEmails=myRS.RecordCou
response.Write TotalEmails
response.end
MyConn.Close
Header.lblHeaderLeft.Value
I am sure there is an easier way of doing this. Would be grateful for anyone's help.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Glad we could help.
ASKER
Thanks so much for your help.
Could not get deathtospam's SQL to work, but pasted jman's in its place and the combined code is excellent.
Thank you both again. Have divided the points.
Brian