Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
MevaD
Starting Member
32 Posts |
Posted - 2010-09-27 : 14:23:03
|
| Hi,Is it possible to order my results by Expected Completion Date of the Root Task and still maintain the Parent-Child list? Please see below:Using SQL 2005The Table: TasktaskID int,parentID int,projID int,title char(30) expCompDate datetimeThe Query:SELECT Task.TaskID, Task.ParentTaskID, t2.ParentTaskID AS [GrandParent], Task.Title, t3.ExpCompDateFROM pt_TaskLEFT JOIN Task t2 on Task.ParentTaskID = t2.TaskIDLEFT JOIN Task t3 on Task.TaskID = t3.TaskID and t3.ParentTaskID is NULLWHERE Task.ProjID = @projIDOrder By Coalesce(t2.ParentTaskID, pt_Task.ParentTaskID, Task.TaskID), Coalesce(Task.ParentTaskID, Task.TaskID), Coalesce(Task.ParentTaskID, 0)Current Results:7 NULL NULL Task 7 2010-11-30 00:00:00.00010 7 NULL Task 10 NULL11 NULL NULL Task 11 2010-10-31 00:00:00.0009 11 NULL Task 9 NULL13 11 NULL Task 13 NULL14 13 11 Task 14 NULL12 NULL NULL Task 12 1900-01-01 00:00:00.000--------------------------------------------------This is what I would like to get as a result set (Ordered By ExpCompDate AND Parents and children still together.)12 NULL NULL Task 12 1900-01-01 00:00:00.00011 NULL NULL Task 11 2010-10-31 00:00:00.0009 11 NULL Task 9 NULL13 11 NULL Task 13 NULL14 13 11 Task 14 NULL7 NULL NULL Task 7 2010-11-30 00:00:00.00010 7 NULL Task 10 NULLThanks! |
|
|
|
|
|
|
|