用于创建网络图/甘特图的SQL递归更新查询

时间:2019-01-15 06:20:06

标签: sql-server

根据下表结构需要以下结果。

结果: ProjectUID TaskUID TaskName MastID MastName ChildID ChildName LNK LnkType级别 1 1 T1 1 T1空NULL P空1 1 6 T6 6 T6空NULL S空2 1 1 T1 1 T1 6 T6 S SS 1 1 2 T2 2 T2 6 T6 S SS 3 1 5 T5 5 T5 6 T6 S FS 1 1 1 T1 1 T1 2 T2 S SS 1 1 2 T2 2 T2 1 T1 P SS 3 1 3 T3 3 T3 1 T1 P FS 4 1 4 T4 4 T4 1 T1 P SS 1 1 6 T6 6 T6 1 T1 P SS 2 1 5 T5 5 T5 4 T4 P SS 1 1 3 T3 3 T3 2 T2 P FS 4 1 5 T5 5 T5 2 T2 P SF 1 1 6 T6 6 T6 2 T2 P SS 2 1 2 T2 2 T2 5 T5 S SF 3 1 4 T4 4 T4 5 T5 S SS 1 1 1 T1 1 T1 4 T4 S SS 1 1 3 T3 3 T3 4 T4 S FF 4 1 4 T4 4 T4 3 T3 P FF 1 1 5 T5 5 T5 4 T4 P SS 1 1 1 T1 1 T1 2 T2 S SS 1 1 1 T1 1 T1 3 T3 S FS 1 1 2 T2 2 T2 3 T3 S FS 3 1 6 T6 6 T6 5 T5 P FS 2 1 4 T4 4 T4 3 T3 P FF 1 1 6 T6 6 T6 5 T5 P FS 2 1 5 T5 5 T5 4 T4 P SS 1 1 1 T1 1 T1 2 T2 S SS 1 1 6 T6 6 T6 5 T5 P FS 2 1 6 T6 6 T6 5 T5 P FS 2

表结构以及示例数据

创建表#NetworkDiagram ( ProjectUID VarChar(200), TaskUID VarChar(200), 任务名称VarChar(200), MastID VarChar(200), 桅杆名称VarChar(200), ChildID VarChar(200), ChildName VarChar(200), LNK VarChar(1), LNK类型VarChar(2) ) 插入#NetworkDiagram ( ProjectUID, TaskUID, 任务名称, MastID, 桅杆名称, ChildID, ChildName, LNK, LNK类型 ) 插入A (ProjectUID,TaskUID,Taskname,MastID,MastName,ChildID,ChildName,LNK,LNKType) 价值观 ('1','1','T1','1','T1','2','T2','S','SS'), ('1','1','T1','1','T1','3','T3','S','FS'), ('1','1','T1','1','T1','4','T4','S','SS'), ('1','1','T1','1','T1','6','T6','S','SS'), ('1','1','T1','1','T1',NULL,NULL,'P',NULL), ('1','2','T2','2','T2','1','T1','P','SS'), ('1','2','T2','2','T2','3','T3','S','FS'), ('1','2','T2','2','T2','5','T5','S','SF'), ('1','2','T2','2','T2','6','T6','S','SS'), ('1','3','T3','3','T3','1','T1','P','FS'), ('1','3','T3','3','T3','2','T2','P','FS'), ('1','3','T3','3','T3','4','T4','S','FF'), ('1','4','T4','4','T4','1','T1','P','SS'), ('1','4','T4','4','T4','3','T3','P','FF'), ('1','4','T4','4','T4','5','T5','S','SS'), ('1','5','T5','5','T5','2','T2','P','SF'), ('1','5','T5','5','T5','4','T4','P','SS'), ('1','5','T5','5','T5','6','T6','S','FS'), ('1','6','T6','6','T6','1','T1','P','SS'), ('1','6','T6','6','T6','2','T2','P','SS'), ('1','6','T6','6','T6','5','T5','P','FS'), ('1','6','T6','6','T6',NULL,NULL,'S',NULL)

0 个答案:

没有答案