0

Example:

CREATE PROCEDURE test (@age int) AS BEGIN
BEGIN TRAN

declare @flag int

if @age>20
begin
set @flag=1
end

else if @age<21
begin
set @flag=0
end

select @flag as flag

COMMIT TRAN
END

I need to fetch the @flag's value using php, how can I make this possible?

$row=mssql_fetch_array($r, MSSQL_ASSOC); $flag=$row['flag'];

EDIT: Never mind, it wasn't working because I forgot to delete some output queries in my procedure.

Thanks anyways ;)

1 Answer 1

1

@flag is a local variable to the procedure. The best way to return a value is to use an output parameter:

CREATE PROCEDURE test (@age int, @flag int output) AS
BEGIN
    set @flag = (case when @age > 20 then 1 else 0 end);
END;

I don't see why a transaction would be necessary or desirable in this case.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.