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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:14:45+00:00 2026-05-25T12:14:45+00:00

I have a stored procedure like this, USE MyDataBaseName GO CREATE PROCEDURE h_sp_find_exist @in_name

  • 0

I have a stored procedure like this,

USE MyDataBaseName
GO
CREATE PROCEDURE h_sp_find_exist
@in_name varchar,@in_counterparty varchar,
@out_recordsNum int OUTPUT
AS
BEGIN
SELECT @out_recordsNum = COUNT(*)
    FROM TMyTableName
    WHERE Name=@in_name AND Counterparty=@in_counterparty
RETURN @out_recordsNum 
END

I always get 0 from the return value.
What’s wrong with it?

The execute code:

use MyDataBaseName
go
declare @retRecordNum int
execute h_sp_find_exist 'myName', '50139', @retRecordNum OUTPUT
select @retRecordNum as 'RecordNumber'

if I just run the sql code,
select count (*)
where name=’myName’ and counterparty=’50139′, it works, and result is 1

  • 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-25T12:14:46+00:00Added an answer on May 25, 2026 at 12:14 pm

    Your input parameters are being truncated, because you’ve not supplied a length for varchar, and the default is 1. (You also as others have said, don’t need the return statement):

    CREATE PROCEDURE h_sp_find_exist
    @in_name varchar(20),@in_counterparty varchar(20), --<-- changes here
    @out_recordsNum int OUTPUT
    AS
    BEGIN
    SELECT @out_recordsNum = COUNT(*)
        FROM TMyTable
        WHERE Name=@in_name AND Counterparty=@in_counterparty
    END
    

    Return sets the exit code for the stored procedure. This can only ever be an integer, and would generally be used to indicate success or failure. You can obtain the value from a return by assigning it as part of your exec statement:

    declare @retRecordNum int
    declare @returnCode int
    execute @returnCode = h_sp_find_exist 'myName', '50139', @retRecordNum OUTPUT
    select @retRecordNum as 'RecordNumber'
    

    Here, @returnCode would be assigned whatever value was passed to the return statement

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

Sidebar

Related Questions

Say we have stored procedure(s) performing simple operations like this: CREATE PROCEDURE [dbo].[AddNewAuthorReturnID] (
I have a line in my SQL Stored Procedure that looks like this (works
I have a stored procedure with an IN OUT parameter declared like follows: create
I have a stored procedure that returns multiple resultsets, it looks something like this
I've got a mySql stored procedure that looks like this-- delimiter | create procedure
Say I have a stored procedure GetAddressInfo(addressId int, errorCode int output) . The stored
I have a Stored Procedure that look like this BEGIN insert into `TheSomaProject`.`Projects` (
I want to (loosely) have a stored procedure like select * from table where
I have a stored procedure which basically does something like select top 1 expiryDate,
I would like to have a stored procedure that return 3 results. these results

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.