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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:47:51+00:00 2026-05-28T03:47:51+00:00

Using stored procedure output for a parameter of a function DECLARE @SeqNo int; DECLARE

  • 0

Using stored procedure output for a parameter of a function

DECLARE @SeqNo int; 
DECLARE @CharNumber varchar(10);
EXEC  dbo.sp_GetNextCounter 'ITEMTYPE', @SeqNo OUTPUT;
EXEC @CharNumber=dbo.rf_f_CIntToChar @SeqNo, 6;
SELECT @CharNumber;

The stored procedure sp_GetNextCounter has an integer output called SeqNo.

The stored procedure:

@param0 varchar(12),
@SeqNo INT OUTPUT
AS
BEGIN
IF (@param0 IS NOT NULL)
BEGIN
    set nocount on
    DECLARE @reqseqno INT
    SELECT @reqseqno = CounterValue FROM Counters WHERE CounterName = @param0
    UPDATE Counters SET CounterValue = @reqseqno + 1 WHERE CounterName = @param0
    SELECT @reqseqno AS 'SeqNo'
END
END
GO

The function dbo.rf_f_CIntToChar takes two parameters (integer to convert, number of characters to return) returns a varchar version of the integer with leading zeros.

The function:

(@intVal int, @intLen int)
RETURNS varchar(10)
WITH EXEC AS CALLER
AS
BEGIN
IF @intlen > 20 SET @intlen = 20
IF @intlen < LEN(@intVal) RETURN RIGHT(CONVERT(varchar(10), @intVal), @intlen)
RETURN REPLICATE('0', @intLen - LEN(@intVal)) + CONVERT(varchar(10), @intVal)
END
GO

Both the stored procedure and the function operate as they should when used separately.

Why does the above query return SeqNo rather than CharNumber?

  • 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-28T03:47:52+00:00Added an answer on May 28, 2026 at 3:47 am

    Your stored procedure never assigns a value to the output parameter @SeqNo

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

Sidebar

Related Questions

I have a stored procedure that returns a varchar(160) as an output parameter of
I have a stored procedure with an output parameter. How do I read this
Possible Duplicate: SQL Server Full text Index SQL Server stored procedure parameter output I
How can I ignore an output parameter of a stored procedure? I'm calling the
I'm using the Oracle command dbms_output.get_line to retrieve output from a stored procedure. Once
I have this stored procedure CREATE PROCEDURE [dbo].[TestProcedure] @param1 int = 0 ,@param2 int
I am using the stored procedure below for the select command of a SqlDataSource,
I have just created a report in Report Manager using a Stored Procedure which
Entity framework is cripplingly slow so I tried using a stored procedure but I
In asp.net(C#) i want to fetch data from a database using a stored procedure

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.