I have the below SQL query:
SELECT CONVERT(varchar, st_duedate, 103) as 'Due Date',
CASE
WHEN st_duedate < GETDATE() THEN 'Overdue'
WHEN st_duedate = GETDATE() THEN 'Due Today'
WHEN DATEDIFF(day,st_duedate,getdate()) <= 7 THEN 'Due within 7 Days'
WHEN DATEDIFF(day,st_duedate,getdate()) > 7 THEN 'Due after 7 Days'
END AS 'Due when'
FROM st_1
However, st_duedate
dates that are dated today are coming up as 'Overdue' and anything after today comes up as 'Due within 7 days' even if the date is months away.
Is it something to do with the converting of the date? I've just tried having st_duedate
as the column name instead of converting but still have the same issue.
Any help would be highly appreciated!