表A(字段:RecordID,ParentID)与表A关联,如果当前记录的ParentID为0则显示本记录的recordID,否则显示父记录的RecordID
表A(字段:RecordID,ParentID)与表A关联,如果当前记录的ParentID为0则显示本记录的recordID,否则显示父记录的RecordID,哪位仁兄知道如何写?请指点指点,非常感谢!
[解决办法]
try
Select
T1.RecordID,
T1.ParentID,
(Case T1.ParentID When 0 Then T1.ProjectName Else T2.ProjectName End) As ProjectName
From
A T1
Inner Join
A T2
On T1.ParentID = T2.RecordID
[解决办法]
不好意思,寫錯了,用Left Join
Select
T1.RecordID,
T1.ParentID,
IsNull(T2.ProjectName, T1.ProjectName) As ProjectName
From
A T1
Left Join
A T2
On T1.ParentID = T2.RecordID