Question
Record Count - SQLDB Query
ASP VB SQL
I want the DB to tell me how many 'WIDGETS' (#) are in each 'STATE' (CA, FL, NY, etc.).
To pull a single 'STATE' my query might look like this:
<%
set rs = Server.CreateObject("ADODB.Recordset")
rs.ActiveConnection = MM_cnConn_STRING
rs.Source = "SELECT count(*) AS TotalWIDGETS FROM dbo.Database WHERE STATE = 'FL'"
rs.CursorType = 0
rs.CursorLocation = 2
rs.LockType = 3
rs.Open()
rs_numRows = 0
%>
<%
' *** Recordset Stats, Move To Record, and Go To Record: declare stats variables
' set the record count
rs_total = rs.RecordCount
' set the number of rows displayed on this page
If (rs_numRows < 0) Then
rs_numRows = rs_total
Elseif (rs_numRows = 0) Then
rs_numRows = 1
End If
' set the first and last displayed record
rs_first = 1
rs_last = rs_first + rs_numRows - 1
' if we have the correct record count, check the other stats
If (rs_total <> -1) Then
If (rs_first > rs_total) Then rs_first = rs_total
If (rs_last > rs_total) Then rs_last = rs_total
If (rs_numRows > rs_total) Then rs_numRows = rs_total
End If
%>
<%
' *** Recordset Stats: if we don't know the record count, manually count them
If (rs_total = -1) Then
' count the total records by iterating through the recordset
rs_total=0
While (Not rs.EOF)
rs_total = rs_total + 1
rs.MoveNext
Wend
' reset the cursor to the beginning
If (rs.CursorType > 0) Then
rs.MoveFirst
Else
rs.Requery
End If
' set the number of rows displayed on this page
If (rs_numRows < 0 Or rs_numRows > rs_total) Then
rs_numRows = rs_total
End If
' set the first and last displayed record
rs_first = 1
rs_last = rs_first + rs_numRows - 1
If (rs_first > rs_total) Then rs_first = rs_total
If (rs_last > rs_total) Then rs_last = rs_total
End If
%>
MY QUESTION IS....
How can I have it pull the total record count for all 50 'STATE' categories so that I receive a page with information like this:
FL: {rs_total}
CA: {rs_total}
NY: {rs_total}
TX: {rs_total}
VA: {rs_total}
PA: {rs_total}
etc.
etc.
etc.
I want the DB to tell me how many 'WIDGETS' (#) are in each 'STATE' (CA, FL, NY, etc.).
To pull a single 'STATE' my query might look like this:
<%
set rs = Server.CreateObject("ADODB.Recordset")
rs.ActiveConnection = MM_cnConn_STRING
rs.Source = "SELECT count(*) AS TotalWIDGETS FROM dbo.Database WHERE STATE = 'FL'"
rs.CursorType = 0
rs.CursorLocation = 2
rs.LockType = 3
rs.Open()
rs_numRows = 0
%>
<%
' *** Recordset Stats, Move To Record, and Go To Record: declare stats variables
' set the record count
rs_total = rs.RecordCount
' set the number of rows displayed on this page
If (rs_numRows < 0) Then
rs_numRows = rs_total
Elseif (rs_numRows = 0) Then
rs_numRows = 1
End If
' set the first and last displayed record
rs_first = 1
rs_last = rs_first + rs_numRows - 1
' if we have the correct record count, check the other stats
If (rs_total <> -1) Then
If (rs_first > rs_total) Then rs_first = rs_total
If (rs_last > rs_total) Then rs_last = rs_total
If (rs_numRows > rs_total) Then rs_numRows = rs_total
End If
%>
<%
' *** Recordset Stats: if we don't know the record count, manually count them
If (rs_total = -1) Then
' count the total records by iterating through the recordset
rs_total=0
While (Not rs.EOF)
rs_total = rs_total + 1
rs.MoveNext
Wend
' reset the cursor to the beginning
If (rs.CursorType > 0) Then
rs.MoveFirst
Else
rs.Requery
End If
' set the number of rows displayed on this page
If (rs_numRows < 0 Or rs_numRows > rs_total) Then
rs_numRows = rs_total
End If
' set the first and last displayed record
rs_first = 1
rs_last = rs_first + rs_numRows - 1
If (rs_first > rs_total) Then rs_first = rs_total
If (rs_last > rs_total) Then rs_last = rs_total
End If
%>
MY QUESTION IS....
How can I have it pull the total record count for all 50 'STATE' categories so that I receive a page with information like this:
FL: {rs_total}
CA: {rs_total}
NY: {rs_total}
TX: {rs_total}
VA: {rs_total}
PA: {rs_total}
etc.
etc.
etc.
