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 6787341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:21:17+00:00 2026-05-26T17:21:17+00:00

I wrote a stored procedure which returns contract status for anauthor. If author doesn’t

  • 0

I wrote a stored procedure which returns contract status for anauthor. If author doesn’t exist i’ll return -900. So, this is what i did

  CREATE PROCEDURE AUthorContract
    @user varchar(10)
       AS
          IF(@user NOT IN(select Au_id from Authors))
           BEGIn
               RETURN -900
          END
      ELSE
       BEGIN
         select contract from from Authors where Au_id = @user
       END

       GO

However, when I give a valid author id as input, it returns -900 and if i give some id it goes into else and just returns 0 . So, I reversed them and entered correct id, but it still just returns 0 and not the contract value.
Can u please help me out the mistake i have been doing. The DB is pubs.

  • 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-26T17:21:17+00:00Added an answer on May 26, 2026 at 5:21 pm

    stored procedure can “return” three types of things:

    • int return value, via RETURN command
    • output parameter value, via parameter list: @YourPartameter anydatatype OUTPUT
    • result set: SELECT * FROM YourTable

    your procedure does not have a RETURN command for normal exit, so it defaults to a value of zero. You need to check the result set in your application if the return value is zero.

    try this to RETURN the contact value:

    CREATE PROCEDURE AUthorContract
        @user varchar(10)
           AS
           DECLARE @contract int
              IF(@user NOT IN(select Au_id from Authors))
               BEGIn
                   RETURN -900
              END
          ELSE
           BEGIN
             select @contract=contract from from Authors where Au_id = @user
           END
    
           RETURN @contract
    
           GO
    

    try this to use an OUTPUT parameter:

    CREATE PROCEDURE AUthorContract
        @user varchar(10), @contract varchar(30) OUTPUT
           AS
              IF(@user NOT IN(select Au_id from Authors))
               BEGIn
                   RETURN -900
              END
          ELSE
           BEGIN
             select @contract=contract from from Authors where Au_id = @user
           END
    
           RETURN 0
    
           GO
    

    Here is the result set, with an explicit return:

    CREATE PROCEDURE AUthorContract
        @user varchar(10)
           AS
              IF(@user NOT IN(select Au_id from Authors))
               BEGIn
                   RETURN -900
              END
          ELSE
           BEGIN
             select contract from from Authors where Au_id = @user
           END
    
           RETURN 0
    
           GO
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

here's the stored procedure i wrote.In this proc p_subjectid is an array of numbers
Well I have this MySQL stored procedure that I wrote and if I run
I need a stored procedure which will allow me to return sorted results based
In my Script Component, am trying to execute Stored Procedure => which return multiple
I have a data access layer which returns DataSets/DataTables by executing Stored Procedure. Everything
I want to call the Stored Procedure which returns a table in the Table
Someone in my company wrote a closed stored procedure which gives these results: rowNumber
I have a stored procedure which returns a mixture of plain columns, and one
i need to write a stored procedure which will return a string.logic is when
Let's say I have a stored procedure which returns a large set of data.

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.