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

  • SEARCH
  • Home
  • 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 7934501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:40:03+00:00 2026-06-03T21:40:03+00:00

If you run the exec stored procedure command in SSMS, it produces this script:

  • 0

If you run the exec stored procedure command in SSMS, it produces this script:

USE [MY_DB]
GO

DECLARE @return_value int

EXEC    @return_value = [dbo].[usr_DailyReportsEmpty]
        @username = N'someuser'

SELECT  'Return value' = @return_value

GO

However when I run the script the EXEC returns 16 and the SELECT returns 0. Why is that?

  • 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-06-03T21:40:05+00:00Added an answer on June 3, 2026 at 9:40 pm

    You need to change the procedure to explicitly RETURN the value you wish to capture. As Barry Kaye mentioned above when you simply select a value to return a result set the procedure returns 0 for success but if you use the RETURN statement the procedure will return that value.

    In the following example, 1 will be selected as a result set when the first procedure is executed but the value captured in @return1 will be 0 for success. The second procedure will not have a result set and the value captured in @return2 will be 3.

    CREATE PROCEDURE Test1
    AS
        SELECT 1;
    GO
    
    CREATE PROCEDURE Test2
    AS
        RETURN 3;
    GO
    
    DECLARE @return1 INT, @return2 INT;
    EXEC @return1 = Test1;
    EXEC @return2 = Test2;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

ALL stored procedure USE [amozeshgah] GO /****** Object: StoredProcedure [dbo].[selectmanageregistercourse] ******/ SET ANSI_NULLS ON
hy, in my script i run a exec() function to make a movie file
Today I run this select 'exec sp_refreshview N''['+table_schema+'].['+table_name+']''' from information_schema.tables where table_type = 'view'
I am trying to run this code : exec myStoredProcedure Cast('c5b48202-36af-4597-9780-5366d4188f55' AS uniqueidentifier), 744,
Can I run a PHP CGI script as a background process using exec() ?
I'm trying out the Runtime.exec() method to run a command line process. I wrote
I'm attempting to run the following command in PHP (on Ubuntu): <?php if (exec(/home/johnboy/ffmpeg/ffmpeg
I have the next query that I run via SQLCMD.EXE use [AxDWH_Central_Reporting] GO EXEC
Another developer created a stored procedure that is set up to run as a
I'm trying to run a stored procedure from my website that disables a trigger.

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.