Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6004263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:14:20+00:00 2026-05-23T01:14:20+00:00

In testing output values from procs, why does the final select @TestValOut return 0

  • 0

In testing output values from procs, why does the final select @TestValOut return 0 instead of null or an empty string?

I understand the correct way to do this is by using OUTPUT parameters, so the question really becomes: Why is the datatype of the set value of @TestValOut, at execution, an integer?

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'Custom.test') AND type in (N'P', N'PC'))
    DROP PROCEDURE Custom.test
GO

CREATE PROCEDURE Custom.test (
    @CurrentUserID INT = 1
    )
As
    Declare @TestValIn varchar(max)
    select @TestValIn='asdf'

GO

BEGIN TRAN

    Declare @TestValOut varchar(max)
    set @TestValOut='ffff'
    Exec @TestValOut=Custom.test @CurrentUserID=1
    select @TestValOut
ROLLBACK
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:14:20+00:00Added an answer on May 23, 2026 at 1:14 am

    A return value in a stored procedure is always an integer, as a matter of fact you can only use an integer with a return value. The fact that you see 0 means the proc executed correctly, this is the return value that SQL Server returns telling you what the result of the proc execution is

    For fun do a select 1/0 in the proc and you will see it won’t be 0 anymore

    See here

    Is a return value of 0 always a success in stored procedures?

    here are the examples from that answer

    CREATE PROC pr_test AS 
    SELECT 1/0
    
    RETURN 0
    GO
    

    Now run it

    DECLARE @i INT
    exec @i = pr_test
    
    SELECT @i  -- will be 0
    
    DROP PROC pr_test
    

    Now let’s do it again without the return statement

    CREATE PROC pr_test2 AS 
    SELECT 1/0
    
    GO
    
    DECLARE @i INT
    exec @i = pr_test2
    
    SELECT @i  -- will be - 6
    

    Better to use an output parameter to pass back statuses and or messages

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Testing: return request.getCookies() == null; is not an appropriate way test. Is there another
From the isset() docs : isset() will return FALSE if testing a variable that
I'm using the mock-0.6 library from http://www.voidspace.org.uk/python/mock/mock.html to mock out a framework for testing,
I was just testing Output Caching in the RC build of ASP.NET MVC 3.
I'm trying to understand how unit testing works. So far i understand you're testing
I'm testing my site where i use ob_gzhandler to compress output and got an
Unit testing and ASP.NET web applications are an ambiguous point in my group. More
Unit testing is, roughly speaking, testing bits of your code in isolation with test
For testing purposes I have to generate a file of a certain size (to
Unit testing sounds great to me, but I'm not sure I should spend any

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.