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)
 Finding MaxID from the table....SP

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-06-18 : 09:41:44
Dharma writes "Hi there!
I am getting the following error when I run the following SP.

Server: Msg 137, Level 15, State 1
[Microsoft][ODBC SQL Server Driver][SQL Server]Must declare the variable '@maxid'.




code:----------------------------------------------------

CREATE Procedure spFindMax @tablename varchar(50), @pykey varchar(50) As
Declare @SqlStr varchar(1000) , @maxid int
set @SqlStr ='Select @maxid=ISNULL(max('+ @pykey + '),0) From ' + @tablename
Exec (@SqlStr)
print @maxid

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


Please help me. Thanx in advance."
   

- Advertisement -