Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 using select max(column) in Stored procedures

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-01-23 : 10:12:11
steve writes "Hi guys, great site.
My question is this:

I have a stored procedure that i am calling from an asp page. The stored procedure Inserts a new record into database, then I want it to retreive the ID the new column has received. Here is the syntax i am using:

------------------------------------------------

create procedure myinsert (@mydata varchar)
as
Begin
--insert data
Insert into mytable (name) Values (@mydata)

--get the new id
Select max(id) as theMaxid from mytable
end
-------------------------------------------------

The problem is, on my asp page I say =rs("theMaxId") and I get
"... could not locate ordinal...".

Now, if I put "Select max(id) + 1 as theMaxid from mytable" before the insert, it works fine.

Sorry for such a long question, i guess I was windering if the order of execution would matter in a case like this.

thanks a lot,
Steve"
   

- Advertisement -