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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:04:08+00:00 2026-05-25T18:04:08+00:00

I have a clr stored procedure that has to return decimal value. I cannot

  • 0

I have a clr stored procedure that has to return decimal value. I cannot use output parameters at this moment – i need to reuse the existing library that doesn’t process output parameters.
My stored procedure returns a value – but it loosed decimal digits.
Any ideas why?
Thanks,
Jenny

[SqlProcedure]
public static int CalculateMyValue(SqlDecimal aInput1, SqlString aInput2, SqlDecimal aInput3)
{
    try
    {
        //convert second value to code.  call regular stored procedure
        SqlConnection conn = new SqlConnection("context connection=true");
        SqlCommand cmd = new SqlCommand("sp_getCodeForVal", conn);
        cmd.Parameters.AddWithValue("@MyParam", aInput2);
        cmd.CommandType = CommandType.StoredProcedure;
        conn.Open();
        object input2CodeSql = cmd.ExecuteScalar();
        conn.Close();

        if (input2CodeSql == null)
        {
            // debug print
            SqlContext.Pipe.Send(string.Format("aInput2 = {0}", aInput2));
            return 2;
        }

        decimal input2Code = Convert.ToDecimal(input2CodeSql.ToString());
        decimal input1Val = aInput1.Value;
        decimal input3Val = aInput3.Value;

        GetMyDecimal myVal = new GetMyDecimal();
        decimal decValue = myVal.Calculate(input1Val, input2Code, input3Val);
        //debug
        SqlContext.Pipe.Send(string.Format("decValue = {0}", decValue));

        // Create a record object that represents an individual row, including it's metadata.
        SqlDataRecord record = new SqlDataRecord(new SqlMetaData("decValue", SqlDbType.Decimal));

        // Populate the record.
        record.SetDecimal(0, decValue);

        // Send the record to the client.
        SqlContext.Pipe.Send(record);

        return 0;
    }
    catch (Exception)
    {
        return 2;
    }
}

EDIT: forgot to add that SqlContext.Pipe.Send(string.Format(“decValue = {0}”, decValue));
shows decimal places but SqlContext.Pipe.Send(record); returns no decimal places.

  • 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-25T18:04:09+00:00Added an answer on May 25, 2026 at 6:04 pm

    Default decimal’s precicion/scale is 18/0. Try using different overload for creating Meta Data:

    SqlDataRecord record = new SqlDataRecord(new SqlMetaData("decValue", SqlDbType.Decimal, 19, 9, false, false, SortOrder.Ascending, 0));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a CLR stored procedure that takes a value from an arbitrary column
I'm new to this. I'm writing a clr stored procedure that calls another stored
I have a CLR stored procedure that references an assembly created in VS 2008
I have written a CLR stored procedure that is in an assembly. I have
I'm new to SQL CLR programmability. I have a CLR stored procedure that writes
I have a fairly complex CLR stored procedure. What is the best way to
I have created an Excel 2003 add-in that uses the CLR 2.0 and this
From a previous question I have seen that the CLR has workstation and server
I have a stored procedure that needs to pass a result set from another
I have written the following piece of code ( sql clr 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.