Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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
Reply With Quote
  #2 (permalink)  
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
Reply With Quote
  #3 (permalink)  
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
Reply With Quote
  #4 (permalink)  
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
Reply With Quote
  #5 (permalink)  
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 11:10 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.