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)
 eliminate decimal places in formula

Author  Topic 

chapm4
Yak Posting Veteran

58 Posts

Posted - 2012-04-12 : 09:11:33
The following

DECLARE @y date
DECLARE @d date

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

SELECT SUM(hsmTotalHoursWorkedByHourlyEmp + hsmTotalHoursWorkedBySalariedEmp) AS TOTAL_HOURS_YTD
FROM tbl_HealthAndSafetyMonthlyData
WHERE Convert(date,hsmReportingDate) BETWEEN @y AND @d


Returns 942084.000000
How do I make it return 942,084

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2012-04-12 : 09:50:32
Change the format in your presentation layer.









How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

chapm4
Yak Posting Veteran

58 Posts

Posted - 2012-04-12 : 10:19:57
Which seems like


SELECT ROUND(SUM(hsmTotalHoursWorkedByHourlyEmp + hsmTotalHoursWorkedBySalariedEmp),1) AS TOTAL_HOURS_YTD


Would work but it doesn't
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2012-04-12 : 10:29:58
quote:
Originally posted by chapm4

Which seems like


SELECT ROUND(SUM(hsmTotalHoursWorkedByHourlyEmp + hsmTotalHoursWorkedBySalariedEmp),1) AS TOTAL_HOURS_YTD


Would work but it doesn't



If you want an integer value, why are you rounding the value off to a single decimal place?

Try rounding off to 0 decimal places and then casting the result to an integer data type.



CODO ERGO SUM
Go to Top of Page
   

- Advertisement -