question

nidheesh.r.pillai avatar image
nidheesh.r.pillai asked

How to chop-off the decimal digits without allowing the rounding?

In one of the procedures, I have a temp table, designed to be exactly the same as the destination table, wherein the data will be finally dumped. A column of that temp table is rate decimal (6,5) not null I will be storing decimal data into this, which comes computed from another part of the stored procedure, and therefore the digits after the dcimal can sometimes exceed 5 (example 0.01263789). When I try to store data in the rate column, it is getting automatically rounded-off to 0.01264. But I want the final value as 0.01263. Is there a way in SQL Server 2008 that I can simply chop-off the decimal digits without allowing the rounding?
sql-server-2008decimalround
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

Kev Riley avatar image
Kev Riley answered
Use the *function* part of the round function, to specify that you want truncation rather than rounding. e.g. declare @rate decimal (6,5) set @rate = round(0.01263789,5,1) select @rate returns --------------------------------------- 0.01263 (1 row(s) affected) http://technet.microsoft.com/en-us/library/ms175003(v=sql.100).aspx
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.