|
-
Jun 18th, 2001, 06:29 AM
#1
Thread Starter
Hyperactive Member
What's wrong in this code?
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.
-
Jun 18th, 2001, 06:48 AM
#2
Addicted Member
Re: What's wrong in this code?
Dear Jeba,
Well, I have tested ur proc. I have removed the @maxid from the
code and executed it. It works fine.
CREATE Procedure spFindMax @tablename varchar(50), @pykey varchar(50) As
Declare @SqlStr varchar(1000)
set @SqlStr ='Select ISNULL(max('+ @pykey + '),0) From ' + @tablename
Exec (@SqlStr)
Last edited by Venkrishna; Jun 18th, 2001 at 07:10 AM.
there r no alternatives 4 hardwork.
-
Jun 18th, 2001, 06:51 AM
#3
Thread Starter
Hyperactive Member
Dear Venkrishna!
well, thanks for your reply. I wanted to use @maxid as the OUTPUT parameter, so that I can eliminate creation of a recordset.
-
Jun 18th, 2001, 06:53 AM
#4
Addicted Member
there r no alternatives 4 hardwork.
-
Jun 20th, 2001, 04:50 AM
#5
Thread Starter
Hyperactive Member
Hi VB_DBA!
Thanks a lot for the reply. Sorry for disturbing you again...
Instead of printing, can you please return the @maxid as the OUTPUT parameter? I've tried to assign the value of @maxid to another variable, but it is giving an error:
Couldn't assign a varchar value to int datatype.
Please help.
-
Jun 20th, 2001, 07:05 AM
#6
Fanatic Member
Do you have to have it returned as an output parameter? You could do the following and it would return the MaxID as a recordset:
CREATE Procedure spFindMax @tablename varchar(50),
@pykey varchar(50) As
Declare @SqlStr varchar(1000)
Set @SqlStr = ''
set @SqlStr = @SqlStr + 'Select ISNULL(max(' + @pykey + '),0) '
set @SqlStr = @SqlStr + 'From ' + @tablename
Exec (@SqlStr)
Other than doing it this way, I don't believe you are going to be able to use an Output parameter with this type of stored proc.
Chris
-
Jun 20th, 2001, 08:31 AM
#7
Thread Starter
Hyperactive Member
Hi Chris!
It would be better(..the best) if I could return it as Output parameter, because I have to call this Stored procedure in many places. So I feel opening a recordset for each instance is a bit costly. Why can't I assign the @maxid variable to the output parameter?
Pls help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|