Being new in sql not sure if this is the best way so please correct if I am wrong in my thinking.I need to use a number of days since an eventDate in a formula. Need to take number of days since eventDate * (hours worked in 12 months / number of days)I have a field in table that computes number of days and the table is ordered by lastEventDate. So I get my days like thisSELECT TOP 1 (LLT_DAYS)FROM tbl_HAW_HealthAndSafety_LLTORDER BY eveEventDate DESC
I just need to multiply that number (in this case 214) by the result of thisUSE SAFETY_WEBDECLARE @y dateDECLARE @d dateSET @y = DATEADD(m, -12, CURRENT_TIMESTAMP)SET @d = CAST(GETDATE() AS date)SELECT SUM(hsmTotalHoursWorkedByHourlyEmp + hsmTotalHoursWorkedBySalariedEmp) /365 * @x AS AVG_HOURS_DAILY FROM tbl_HealthAndSafetyMonthlyData WHERE Convert(date,hsmReportingDate) BETWEEN @y AND @d
to get my result (in this case the final number is 552334). I have tried to add the first code into the second but doesnt work. How can I do this?