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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL MAX function

Status
Not open for further replies.

boux123

Technical User
Mar 20, 2007
16
0
0
CA
Hi,

I am trying creating a sql query to retrieve the lasted identity # inserted into the table. Here is my code:

"

pdrQuery = "SELECT MAX(pdrNumber) FROM tblPDR"

Set oRsSub2 = oConn.Execute(pdrQuery)

pdrNumber = oRsSub2("pdrNumber")

Response.Write pdrNumber

"

The error is:

Item cannot be found in the collection corresponding to the requested name or ordinal.


I am not too sure how to fix this problem. Please advise.
 
try....

Code:
pdrQuery = "SELECT MAX(pdrNumber) [!]As pdrNumber[/!] FROM tblPDR"

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Do you understand why it works? If you don't, do you want me to explain it?

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top