Using a recursive CTE, you can build the hierarchy. Filtering the top level query by your search criteria, you can get the results you're looking for.
DECLARE @id INT;
SET @id = 3;
WITH Emp
AS (SELECT te.id
, te.Name
, te.ManagerId
, CAST(NULL AS VARCHAR(10)) AS ManagerName
FROM dbo.tblEmployee AS te
-- Get entire heirarchy with the NULL ManagerId
--WHERE ManagerId IS NULL
WHERE te.id = @id
UNION ALL
SELECT te2.id
, te2.Name
, e.id
, e.Name
FROM dbo.tblEmployee AS te2
JOIN Emp e
ON e.id = te2.ManagerId
)
SELECT *
FROM Emp;
UPDATE:
For your comment about not including the record for the id
passed, you can do two things:
The easiest way would be to add a where clause to the last select:
SELECT *
FROM Emp
WHERE emp.ID <> @id;
Alternatively, if you didn't need the ManagerName
field to be populated for the top level of the hierarchy, you can what the first where clause in the CTE:
SELECT te.id
, te.Name
, te.ManagerId
, CAST(NULL AS VARCHAR(10)) AS ManagerName
FROM dbo.tblEmployee AS te
-- Get entire heirarchy with the NULL ManagerId
--WHERE ManagerId IS NULL
--WHERE te.id = @id
WHERE ManagerId = @id