hi i tried running the code below its part of a larger stored procedure to run a payroll. but i get an error message at this point saying Msg 50000, Level 11, State 1, Procedure spPayrollRun, Line 292
Error converting data type varchar to numeric.
Can some help please
MY CODE
SELECT d.Id, SUM(ROUND(CASE WHEN T1.DeductionBase > dtd.AmountTo THEN (dtd.AmountTo - dtd.AmountFrom) WHEN T1.DeductionBase > dtd.AmountFrom
THEN T1.DeductionBase - dtd.AmountFrom ELSE 0 END * (dtd.Rate / 100 * dtd.EmployeeShare / 100),2)) AS EmployeeAmount,
SUM(ROUND(CASE WHEN T1.DeductionBase > dtd.AmountTo THEN (dtd.AmountTo - dtd.AmountFrom) WHEN T1.DeductionBase > dtd.AmountFrom
THEN ISNULL(T1.DeductionBase - NULLIF(dtd.AmountFrom,''),0) END * ISNULL(dtd.Rate / 100 * NULLIF(dtd.EmployerShare / 100,''),0),2)) AS EmployerAmount,
AVG(T1.DeductionBase) AS DeductionBase
FROM T1 JOIN (Deduction d JOIN (DeductionType dt JOIN DeductionTypeDet dtd ON dt.Id = dtd.DeductionTypeId) ON d.DeductionTypeId = dt.Id) ON
T1.StaffId = d.StaffId AND T1.PaymentGroupId = dt.PayGroupId WHERE d.IsActive ='True' AND (d.IsPermanent ='True' OR d.DurationBalance > 0) AND dt.DeductionCategoryId = 'STAT' AND NOT dt.PayGroupId IS NULL AND
EXISTS(SELECT * FROM Staff s WHERE s.Id = d.StaffId AND (s.EndDate IS NULL OR s.EndDate BETWEEN @StartDate AND @EndDate)) AND
EXISTS(SELECT * FROM PayPeriod pp WHERE d.StartDate <= pp.EndDate AND pp.Id =@PayPeriodId) AND NOT EXISTS(SELECT * FROM RepaymentHoliday rh WHERE rh.DeductionTypeId =d.DeductionTypeId AND rh.StaffId =d.StaffId AND rh.PayPeriodId =@PayPeriodId)
GROUP BY d.Id](http://mycode)