January 30, 2002 at 11:33 am
why does this return 0 ???
"select cast((30/364) as dec(20,20))"
Steve Johnson
Steve Johnson
January 30, 2002 at 11:40 am
It thinks that the numbers are int's to start with. Try to do:
select cast((30.0/364.0) as dec(20,20))
That will return the value.
Tom Goltl
January 30, 2002 at 11:47 am
thanks.....
Steve Johnson
Steve Johnson
January 30, 2002 at 9:31 pm
Hi,
I reckon, it picks up everything as int. atleast one of the values should be casted to the final casting.
ie., the final cast is dec(20,20). So, either 30 or 364 should be casted as dec(n,m)
This is just a suggestion.
February 1, 2002 at 5:48 am
Microsoft uses INT as the cast of a number that has no special characters and for some reason they decide if it starts int then the results of math should be the same output, even if overridden. This also happens in C.
February 1, 2002 at 8:11 am
Right. If there's no decimal point, SQL Server will assume the constant to be an integer. Since integer divison should not result in a decimal part (violation of the type), you'll get back only an integer. And this division is occuring before the CAST statement, which means you enter the CAST with a 0. Hence the need to specify 30.0 and 364.0 instead.
K. Brian Kelley
http://www.sqlservercentral.com/columnists/bkelley/
K. Brian Kelley
@kbriankelley
February 1, 2002 at 8:18 am
Thanks again for all the info.... It has been very useful.
Steve Johnson
Steve Johnson
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply