Stored Procedure return values

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
 
N

news.microsoft.com

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.
__________________________________
 
P

Paul

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top