I want to return a varchar(max) from a stored procedure in SQL Server 2008.
So I tried:
alter proc SpSignup(
@username varchar(max),
@email varchar(max),
@password varchar(max),
@warning varchar(max) output)
as
if exists(select email from [login] where email=@email)
return 'email already exists';
insert into [login](username, email, password)
values(@username, @email, @password)
I want to return a varchar value ('email already exists') if the email exists in the table, and don’t want to give any @warning as parameter.
But it shows that @warning para is not supplying after exec this proc
Msg 201, Level 16, State 4, Procedure SpSignup, Line 0
Procedure or function ‘SpSignup’ expects parameter ‘@warning’, which was not supplied.
and also it doesn’t shows the output ('email already exists')
you forgot to supply parameter
@usernameinto your procedureUPDATE: It’s not possible to return
varcharvariable from procedure, you can pass it asoutputparameter or you can just codeselect 'email already exists'orprint 'email already exists'