Question : How To Find the Next 7 Days - T-SQL Code

Discard the long joins written below. I added a column in the last field:

DAY(t.dueDate - getdate()) As DaysLeft

This calculates how many days left prior due date for each record. I need to show
records that have tasks due date after 7 days.

Does the code below constructed correctly?

I didn't create the tables yet, these are just hypothetical tables and fields.

My main question focuses on DAY(t.dueDate - getdate()) As DaysLeft and WHERE DaysLeft = 7;
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
SELECT 
		   pt.projectID,
		   p.name, 
		   ptype.projectType, 
		   p.actualEndDate, 
		   pt.taskID, 
		   t.subject, 
		   t.dueDate,
		   t.percentComplete,
		   s.statusType,
		   c.categoryType,
		   DAY(t.dueDate - getdate()) As DaysLeft
	FROM 
		 ProjectTasks pt 
		 INNER JOIN Project p 
		 ON pt.projectID = p.projectID
		 INNER JOIN Task t 
		 ON pt.taskID = t.taskID
		 INNER JOIN ProjectType ptype 
		 ON ptype.projectTypeID = p.projectTypeID
		 INNER JOIN Status s 
		 ON s.statusID = t.statusID
		 INNER JOIN Category c 
		 ON c.categoryID = t.categoryID
	WHERE DaysLeft = 7;

Answer : How To Find the Next 7 Days - T-SQL Code

try this:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
SELECT 
		   pt.projectID,
		   p.name, 
		   ptype.projectType, 
		   p.actualEndDate, 
		   pt.taskID, 
		   t.subject, 
		   t.dueDate,
		   t.percentComplete,
		   s.statusType,
		   c.categoryType,
		   datediff(DAY,getdate(),t.dueDate) As DaysLeft
	FROM 
		 ProjectTasks pt 
		 INNER JOIN Project p 
		 ON pt.projectID = p.projectID
		 INNER JOIN Task t 
		 ON pt.taskID = t.taskID
		 INNER JOIN ProjectType ptype 
		 ON ptype.projectTypeID = p.projectTypeID
		 INNER JOIN Status s 
		 ON s.statusID = t.statusID
		 INNER JOIN Category c 
		 ON c.categoryID = t.categoryID
	WHERE  datediff(DAY,getdate(),t.dueDate)= -7;
Random Solutions  
 
programming4us programming4us