Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
| Search | Today's Posts | Mark Forums Read
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 28th, 2007, 06:09 PM
Friend of Wrox
Points: 1,243, Level: 13
Points: 1,243, Level: 13 Points: 1,243, Level: 13 Points: 1,243, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2003
Location: , , United Kingdom.
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default Number with 2 decimal places only

Hi,

Using SQL 2000

I have a stored proc that returns a value after some calculations.

The value returned should always include 2 decimal places but this is not happening.

Examples of what it is returning:

2975.0
123.456
34.55
10998.796

As you can see I need to do some adjustments so that it always returns the value with 2 decimal places.

I would appreciate if someone could shed some light on this issue. Is it possible to have this level of control in the stored proc?

This is the last bit of the code I am using to return the value:

if @reportCurrency=1
   begin
     set @calculatedRate = @fltAdRate + ISNULL(@fltPosRate,0)
   end

if @reportCurrency=2
   begin
     set @calculatedRate = (@fltAdRate + ISNULL(@fltPosRate,0))- (@fltAdRate + ISNULL(@fltPosRate,0)) * @agencyDiscount / 100
   end
if @reportCurrency=3
   begin
     set @calculatedRate = (@fltAdRate + ISNULL(@fltPosRate,0))-(@fltAdRate + ISNULL(@fltPosRate,0)) * (@agencyDiscount / 100)
     set @calculatedRate = (@calculatedRate)- (@calculatedRate) * (@cashDiscount /100)
end

 --Output calculated rate
SELECT @calculatedRate as Rate

Cheers
 
Old June 29th, 2007, 12:14 AM
Friend of Wrox
Points: 1,536, Level: 15
Points: 1,536, Level: 15 Points: 1,536, Level: 15 Points: 1,536, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2006
Location: , MI, USA.
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

SELECT CAST(@calculatedRate AS DECIMAL(15,2)) as Rate


--Jeff Moden
 
Old June 29th, 2007, 03:40 AM
Friend of Wrox
Points: 1,243, Level: 13
Points: 1,243, Level: 13 Points: 1,243, Level: 13 Points: 1,243, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2003
Location: , , United Kingdom.
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default

Hi Jeff,

Thanks for the reply.

I can see that the 2 means two decimal places what about the 15?

Cheers
 
Old June 29th, 2007, 07:12 AM
Friend of Wrox
Points: 1,243, Level: 13
Points: 1,243, Level: 13 Points: 1,243, Level: 13 Points: 1,243, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2003
Location: , , United Kingdom.
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default

Hi Jeff,

I have tried the CAST you showed above and it works fine when I use a SELECT statement to return the value.

However, since I am using a user defined function I cannot use the SELECT statement to return a value. I have to use the RETURN statement.

That is what returns the value:

Set @returnVal = ISNULL(CAST(@calculatedRate AS DECIMAL(15,2)), -1)
RETURN @returnVal

This is how I am testing it in query analyser:

select dbo.GetRate( 40, 423, 1, 1, 540, 0, 1)

And get

3725.0

Could you please shed some light?

Cheers
 
Old July 3rd, 2007, 07:29 AM
Friend of Wrox
Points: 1,536, Level: 15
Points: 1,536, Level: 15 Points: 1,536, Level: 15 Points: 1,536, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2006
Location: , MI, USA.
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

The code for the return value returns two decimal places just fine on my box... without seeing the GetRate code, I can't tell what else may be wrong.

--Jeff Moden




Similar Threads
Thread Thread Starter Forum Replies Last Post
How to format numbers with decimal places cyrusds_asp J2EE 2 March 8th, 2013 02:26 AM
Display Decimal Places rsm42 ASP.NET 1.0 and 1.1 Basics 3 January 7th, 2007 10:46 AM
Round to 2 decimal places adman JSP Basics 0 June 30th, 2005 07:24 AM
Two decimal places only pallone Javascript How-To 5 February 2nd, 2005 12:35 AM
output only 2 decimal places Toka1 Javascript How-To 2 February 20th, 2004 11:44 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.