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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:55:51+00:00 2026-06-02T06:55:51+00:00

I am trying to write a stored procedure ( using SQL Server Management Studio

  • 0

I am trying to write a stored procedure ( using SQL Server Management Studio 2008 R2) to retrieve the maximum measurement value from a table. This seemed like an easy thing to do, so I wrote a short stored procedure to get the MAX. However, when I ran the procedure, it returned a 0 rather than the expected 0.018 value.

When I hover my mouse over the MAX function, it displays “built-in function MAX(expression) RETURNS int”. So it seems to be casting my result as an int. This is rather annoying.

I guess I’ll have to calculate the maximum the long way unless anyone here has an easier solution. Any ideas?

ALTER PROCEDURE [dbo].[GetMaxOscillation] (@SerialNumber varchar (16), @Date datetime)
AS
BEGIN
    SET NOCOUNT ON;

    DECLARE @MaxOsc DECIMAL(18,6)

    SELECT @MaxOsc = MAX(Value)
    FROM LoadListingOscillations
    WHERE SerialNumber=@SerialNumber AND Date=@Date AND Value IS NOT NULL


    RETURN @MaxOsc

    SET NOCOUNT OFF
END
  • 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-02T06:55:52+00:00Added an answer on June 2, 2026 at 6:55 am

    You have to do MAX(CAST(Value AS DECIMAL(18,6)))

    I am guessing that the Value is not a DECIMAL, so you must cast it before the assignment

    Here is the SQLFiddle to prove that if the table is set up as a Decimal then this will work

    Here is a SQLFiddle that shows that the cast is needed

    UPDATE

    If Value is indeed a Decimal(18,6), then you need to make sure of your table values. Because, as you can see from my examples, this should work

    The last thing that is probably more your problem is that you are returning an integer. I do not think you can return anything but an integer in SQL Server. You will have to do a SELECT @MaxOsc or use an OUTPUT variable

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

Sidebar

Related Questions

I'm trying to write a fairly simple stored procedure in sql server. If the
Using SQL Server 2008 Reporting services: I'm trying to write a report that displays
I'm trying to write a stored procedure in SQL Server that will eliminate some
I am trying to write a stored procedure in sql server 2005 which will
I am trying to write a Stored Procedure in SQL Server (2005) to do
I'm trying to write a stored procedure [SQL 2008] with a dynamic, auto incrementing
I am trying to write a stored procedure which selects columns from a table
I'm trying to write a stored procedure in SQL that will : Make a
I am trying to write some integration tests for some SQL server stored procedures
I'm trying to write a stored procedure to copy a subset of data from

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.