I have the following number in SQL Server 2008: 5.4564556I just want to get only 4564556 from 5.4564556it would be better if I could only get 4 out of 4564556, which is the first digit of the fractional part.
How can i do this?
thanks
you can get the first four decimal parts:
select SUBSTRING (PARSENAME(5.4564556,1), 1, 4)
You can try this way:
SELECT (5.4564556 % 1)
You can also use FLOOR () :
SELECT Value - FLOOR(Value)
In your case:
5.4564556 - 5 = 0.4564556
in case of a negative value, you can use ABS
SELECT ABS(Value) - ABS(FLOOR(Value))
To get all numbers for ".", You can (ab) use PARSENAME
select PARSENAME(5.4564556,1)
returns 4564556
See also SQL - How to get only numbers after decimal number?
try it
select cast(5.4564556 % 1 * 10 as int)