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
 Transact-SQL (2008)
 limit decimal places in formula

Author  Topic 

chapm4
Yak Posting Veteran

58 Posts

Posted - 2012-05-11 : 10:30:22
I have

--Rolling 12 Month RIR
DECLARE @y date
DECLARE @d date

SET @y = DATEADD(m, -12, CURRENT_TIMESTAMP)
SET @d = CAST(GETDATE() AS date)

SELECT (COUNT(*) * 200000) / 942084.0 AS R12RIR
FROM tbl_HAW_HealthAndSafety_LRI
WHERE Convert(date, EventDate) BETWEEN @y AND @d
GO

That returns 0.63688588
I need it to round off and display 0.64 or .64 but don't know how. Please help.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2012-05-11 : 10:32:23
Use ROUND or CAST functions.



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2012-05-11 : 10:35:45
[code]-- Rolling 12 Month RIR
DECLARE @From DATE = DATEADD(MONTH, -12, GETDATE()),
@To DATE = GETDATE()

SELECT CAST(200000E / 942084E * COUNT(*) AS DECIMAL(12, 2)) AS R12RIR
FROM dbo.tbl_HAW_HealthAndSafety_LRI
WHERE EventDate >= @From
AND EventDate < @To[/code]


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

chapm4
Yak Posting Veteran

58 Posts

Posted - 2012-05-11 : 10:47:41
Thanks so much. After your first answer, I was trying the round function
which I had tried before but was coming up with 0.64000000.
Go to Top of Page
   

- Advertisement -