views:

177

answers:

3

Hi there,

I use SQL Server 2005 and need to test whether values in a column that's metadata has been specified as DECIMAL(18.3) actually contains data that has values to the right of the Decimal point, and if so, what these values are.

I've read a few articles that only discuss how to drop off the decimal places or how to round the values, but not how to ONLY display what is stored to the right of the decimal point.

Your help would be greatly appreciated.

Kind Regards,

Ignacio.

+1  A: 

Try:

SELECT a - FLOOR(a)
FROM ...
cletus
+1  A: 
SELECT decimalnumber - FLOOR(decimalnumber) AS decimalpart
FROM mytable
WHERE decimalnumber - FLOOR(decimalnumber) > 0
gkrogers
A: 

This may not always work the way you expect it to. The problem occurs when you have negative numbers. You can think of FLOOR as a type of rounding, where it always rounds down to the next whole number. Floor(3.14) = 3, and Floor(-3.14) = -4.

To get the value of a number after the decimal point, you can use the ParseName function, which will work for positive and negative numbers.

Select ParseName(-3.9876, 1)
Select ParseName(-3.1234, 1)
Select ParseName(3.9876, 1)
Select ParseName(3.1234, 1)
G Mastros
Hi Guys/Gals (if one of the people who replied is one),Thanks for the answers, they pointed me in the right direction. Just a note, to sort out the Negative Number issue: Just add the ABS() function into the mix and voila, problemo resolved.Have a great week further!Ignacio.