Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How many?

Status
Not open for further replies.

BurcBoyar

Programmer
Joined
Feb 18, 2002
Messages
24
Location
TR
I'm using an access database and I need to get the number of records in it without counting them. Can someone help?

Database is like:
(automatic number)- text
(automatic number)- text
(automatic number)- text
...
and so on.

I need to find the ending number.
Thanx for your answers.
 
SELECT MAX(fieldName) FROM tableName
penny1.gif
penny1.gif
 
Well, i couldn't make it...

Should i use it like:
lastrecord = SELECT MAX(fieldname) from databasename

 
If you wanted to get that number into a local variable , then you might use:

dim rs,con,sql,maxNumber
set con = server.createObject("ADODB.Connection")
set rs = server.createObject("ADODB.Recordset")
sql = "SELECT MAX(fieldName) as maxNum FROM tableName"
con.open connectionStringHere
rs.open sql,con
maxNumber = rs("maxNum")
rs.close
con.close
set rs = nothing
set con = nothing
response.write("maxNumber")

:-)
paul
penny1.gif
penny1.gif
 
It worked paul.
Thanx for your help.
 
PROBLEM
the max will work as long as you don't delete any records
i.e.

DB =
1 test
2 test
3 test

SO Max = 3 and total records = 3

now delete the second record

DB =
1 test
3 test

SO Max = 3 and total records = 2

Instead of Max use the Count(*) function

SELECT Count(*) as RecordCount FROM Table
 
cfk:
Well, i didn't try to delete any record. Thanx for your help anyway. I think I'll need it later.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top