Try this (SQL 2005 only):
Declare @ID int, @Dept varchar(max)
Set @ID = 3;
With DeptHier(ID, ParentID)
as
(
Select ID, ParentID
From Dept
Where ID = @ID
union all
Select Dept.ID, Dept.ParentID
From Dept JOIN DeptHier
On Dept.ID = DeptHier.ParentID
)
Select @dept = Coalesce(@dept + '/', '') + d.Name
from Dept d Join DeptHier dh
on d.ID = dh.ID
order by dh.ParentID
select @dept as Dept
Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"