3

Here's psuedo-code for the stored procedure I currently use,

CREATE PROC uspFoo
(
@id int,
@type nvarchar(255),
@status bit output
)
AS
IF ....
SET @status=1
ELSE
SET @status=0
GO

When executing this stored procedure, I am forced to pass an output parameter that will store its return value,

DECLARE @id int, @type nvarchar(255), @status bit
SET @id=..
SET @type=..
EXEC uspFoo @id, @assayType, @status output

PRINT @status

GO

The return value, or in this case status, will either be 0 (false) or 1 (true).

How can I return a value (e.g. bit) directly without having to store it in a temporary output parameter?

1

1 Answer 1

6

In cases like this you can use the return value from the stored procedure. The following should work.

CREATE PROC uspFoo
(
@id int,
@type nvarchar(255)
)
AS
IF ....
  RETURN 1
ELSE
  RETURN 0
GO

To call:

DECLARE @id int, @type nvarchar(255), @status bit
SET @id=..
SET @type=..
EXEC @status=uspFoo @id, @assayType

PRINT @status
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.