Stored Procedure return values

  • Thread starter Thread starter Paul
  • Start date Start date
P

Paul

Hi,

I could'nt see any SQL message group on MSDN so this is
the closest group.

I have a Stored Procedure that takes a UserName as a
paramater and returns 1 if found and 0 if not found.

However, when I execute my SPROC through SQL Analyser it
executes fine but does not return a value.

The only way I can get it to return teh value in SQL
Analyser is to SELECT @Found rather than a return @Found
statement.

CREATE PROCEDURE dbo.CHECK_USER
@UserName varchar(25)
As
DECLARE @Found Int
IF EXISTS(
Select UserName from CalcUser
where UserName = @UserName
)
set @Found = 1
ELSE
set @Found = 0

SELECT @Found
GO
 
I wrote an article on handling output and return value parameters from
stored procedures that should help. See
http://www.betav.com/msdn_magazine.htm. I expect that in this case you'll
want to use a RETURN value to send back the value as follows:

CREATE PROCEDURE dbo.CHECK_USER
@username varchar(25)
As
DECLARE @Found Int
IF EXISTS(Select UserName from CalcUser
WHERE UserName = @username )
RETURN 1
ELSE
RETURN 0
--
____________________________________
Bill Vaughn
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
I tried something similar to below.

How come when I call SPROC from SQL Analyser it does nit
return a value.

Yet instead of using return if I just do a SELECT @Found
As Found it brings back a value??


Thanks,
Paul.
 
Back
Top