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.
Author |
Topic |
chapm4
Yak Posting Veteran
58 Posts |
Posted - 2012-05-11 : 11:12:50
|
I haveDECLARE @From DATE = DATEADD(MONTH, -12, GETDATE()), @To Date = GETDATE(), @LLT_DAYS Intselect TOP 1 @LLT_DAYS = (LLT_DAYS)FROM tbl_HAW_HealthAndSafety_LLTORDER BY eveEventDate DESCSELECT SUM(hsmTotalHoursWorkedByHourlyEmp + hsmTotalHoursWorkedBySalariedEmp) /365 * @LLT_DAYS AS WHSLLT FROM tbl_HealthAndSafetyMonthlyData WHERE Convert(date,hsmReportingDate) BETWEEN @From AND @ToGO That gives me 629310.093144 and I need the result to be 629,310I have tried CAST to get rid of the after the decimal but couldn't get it to work right in using SUM. Hoping there is a way also to put the ',' placeholder in inside of sql. This ends up on an asp page so I maybe could do it there, but would rather do it here. Thanks for the beginner help. |
|
chapm4
Yak Posting Veteran
58 Posts |
Posted - 2012-05-11 : 11:17:43
|
I triedDECLARE @From DATE = DATEADD(MONTH, -12, GETDATE()), @To Date = GETDATE(), @LLT_DAYS Intselect TOP 1 @LLT_DAYS = (LLT_DAYS)FROM tbl_HAW_HealthAndSafety_LLTORDER BY eveEventDate DESCSELECT CAST(SUM(hsmTotalHoursWorkedByHourlyEmp + hsmTotalHoursWorkedBySalariedEmp) /365 * @LLT_DAYS AS char(6)) FROM tbl_HealthAndSafetyMonthlyData WHERE Convert(date,hsmReportingDate) BETWEEN @From AND @ToGO But get "Arithmetic overflow error converting numeric to data type varchar" |
 |
|
chapm4
Yak Posting Veteran
58 Posts |
Posted - 2012-05-11 : 11:24:50
|
I am getting there but still have the comma questionDECLARE @From DATE = DATEADD(MONTH, -12, GETDATE()), @To Date = GETDATE(), @LLT_DAYS Intselect TOP 1 @LLT_DAYS = (LLT_DAYS)FROM tbl_HAW_HealthAndSafety_LLTORDER BY eveEventDate DESCSELECT CAST(SUM(hsmTotalHoursWorkedByHourlyEmp + hsmTotalHoursWorkedBySalariedEmp) /365 * @LLT_DAYS AS numeric(6,0)) FROM tbl_HealthAndSafetyMonthlyData WHERE Convert(date,hsmReportingDate) BETWEEN @From AND @ToGO Returns 629310How do I return 629,310 |
 |
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2012-05-14 : 07:46:16
|
Where do you want to show data? If you use front end application do the formation thereMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|