SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 urgent sql help
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

ahmeds08
Aged Yak Warrior

India
656 Posts

Posted - 08/13/2014 :  06:13:03  Show Profile  Send ahmeds08 a Yahoo! Message  Reply with Quote
hi,
the below query gives the output 0.000
SELECT CAST(99997/100000 AS NUMERIC(18,3))
but i need the output 0.999

please help

Javeed Ahmed

gbritton
Flowing Fount of Yak Knowledge

1130 Posts

Posted - 08/13/2014 :  09:32:01  Show Profile  Reply with Quote
Two problems:

1. the division is of two integers so the decimal places are lost. Add decimal points to the numbers like this:


99997./100000.


2. The result is being rounded to the nearest decimal position.

99997./100000. = .99997

rounding that yields 1.000 which is correct. You either need more decimal places in the result or do it a different way, e.g.


SELECT left(CAST(99997./100000. AS varchar(18)), 5)

SELECT CAST(99997./100000. AS NUMERIC(18,5))


Go to Top of Page

ahmeds08
Aged Yak Warrior

India
656 Posts

Posted - 08/13/2014 :  12:00:09  Show Profile  Send ahmeds08 a Yahoo! Message  Reply with Quote
thanks for the input.
if the particular value comes from a column. how do I add the decimal point?

Javeed Ahmed
Go to Top of Page

gbritton
Flowing Fount of Yak Knowledge

1130 Posts

Posted - 08/13/2014 :  12:23:32  Show Profile  Reply with Quote
type it!
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000