dID dName sdID 1 XYZ Company 0 2 AA dept 1 3 BB dept 1 4 CC dept 1 5 AA.section 2 6 BB.section 3 7 CC.section 4
dID dName sdID NewColumn 1 XYZ Company 0 2 AA dept 1 XYZ Company 3 BB dept 1 XYZ Company 4 CC dept 1 XYZ Company 5 AA.section 2 AA dept 6 bb.section 3 BB dept 7 CC.section 4 CC dept
Select Select dID, dName, sdID, '' NewColumn from [table] where sdID = 0 union all Select B.dID, B.dName, B.sdID, A.dName NewColumn from [table] A Left outer join [table] B on (A.dID = B.sdID) Where B.dID IS NOT NULL
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)