Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Check Child Dependency

$
0
0
I am looking for help writing an elegant t-sql query for following scenario:

In this scenario I have Task and TaskDependency tables. I would like to get a value of 1, 0, -1 based on the TaskStatus and TaskDependency table for each row in Task table. For example for TaskID = 1, there is no dependency in TaskDependency and Task Status = 'Completed' it should return a value of 0. In case of Task.TaskID = 2 it should return value of -1. For Task.TaskID = 5 there is dependency on 2 and 4. Since 2 failed and 4 is completed it should still return value of 0.

Any help would be appreciated.

    Table: Task
    TaskID     TaskStatus
    1    Completed
    2    Failed
    3    Scheduled
    4    Scheduled
    5    Scheduled

    Table: TaskDependency
    TaskID    ParentTaskID
    1    NULL
    2    NULL
    3    2
    5    4
    4    NULL
    5    2

    Expected Result:
    Task.TaskID = 1 should return value of 0.
    Task.TaskID = 2 should return value of -1.
    Task.TaskID = 3 should return value of 0.
    Task.TaskID = 4 should return value of 1.
    Task.TaskID = 5 should return value of 0.

Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>