I have the following table and values:
-- create a table
CREATE TABLE students (
id int NOT NULL,
name nvarchar(256) NOT NULL,
dateField date NULL
);
-- insert some values
INSERT INTO students VALUES (1, 'Ryan', '2019-01-01');
INSERT INTO students VALUES (2, 'Joanna', '2016-01-05');
INSERT INTO students VALUES (3, 'Miles', '2021-01-20');
I have a stored procedure, which is triggered four times every month.
The goal is to have the stored procedure output a result, where I can see the number of years passed since the date in [dateField].
So, for row 1, it should output a result with a new column displaying 3 (since it has now been 3 years since 2019-01-01). For row 2, the result in the new column should be 6 (6 years). For row 3, the output should be 0 (since a year has not gone by since this date).
The above logic is of course assuming that today's date is 2022-01-06 (yyyy-mm-dd).
I do not have an idea on how to do this, so I also appreciate a mere direction of what to do clause-wise.