This may be really simple and I'm probably overthinking it. I have to create a variable that stores the number of employees who have been employed with the company for more than 3 years.
Here's what I came up with since the original table does not have the years stored, only a column with the hire date.
DECLARE @YearsEmployed int,
@Plus3 int,
@EmpCount int
SET @YearsEmployed = (SELECT DATEDIFF(YY,HireDate,GetDate())
FROM employees)
SET @Plus3 = @YearsEmployed > 3
SET @EmpCount = COUNT(@Plus3)
SELECT @EmpCount
I've already gotten the "Incorrect syntax near '>'" error and I'm at a loss on how to proceed. Any assistance would be greatly appreciated.