Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Other SQL Server 2008 Topics
 Truncate

Author  Topic 

malik_1700
Starting Member

14 Posts

Posted - 2008-08-08 : 00:41:13
I have a column having datatype decimal(18,5).After some calculation I get a sequence of numbers in this column like 0.98123 and 0.98456.
from now I want only 4 digits after decimal like 0.9812 and 0.9845
If I insert thses values in column having datatype decimal(18,4) sql server rounds these values which i dont require . I want trunc function of oracle.

like

select trunc(0.98456,4) from dual;

TRUNC(0.98456,4)
----------------
.9845



webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2008-08-08 : 02:52:42
Hi malik,
you can use round() to truncate!
ROUND ( numeric_expression , length [ ,function ] ) -- set function to 1 and truncation occurs

For your example:
declare @dec18_5 decimal(18,5)
declare @dec18_4 decimal(18,4)
select @dec18_5 = 0.98456
select @dec18_4=round(@dec18_5,4,1)
select @dec18_4

Webfred
Go to Top of Page
   

- Advertisement -