Adnan Ahmed
Adnan Ahmed

Reputation: 686

Error in SQL Server stored procedure

I'm learning stored procedures and here is the code that i have written. But its giving error.

Error: Incorrect syntax near '@return'.

My code:

create procedure test (@status varchar(50), @return varchar(50) output)
as
begin
    if @status = 'running'
        begin
            @return = '1'
        end
    else
        begin
            @return = '2'
        end
end

Upvotes: 1

Views: 46

Answers (2)

Dimi Takis
Dimi Takis

Reputation: 4939

It has to be

SET @return='1'

the rest is fine

Upvotes: 1

marc_s
marc_s

Reputation: 754220

You need to actually use SET or SELECT to assign values:

create procedure test (@status varchar(50), @return varchar(50) output)
as
begin
    if @status = 'running'
       SET @return = '1'
    else
       SET @return = '2'
end

Upvotes: 0

Related Questions