create hierarchy using T-SQL!

I have a table which shows categoryID and its parentID like this:
Year   Month    catID       catName                   parentID    
2007      5          1001       PDA & Handhelds     1000
2007      5          1002       PDAs                         1001
2007     5           1003       notebooks                 1000
2007     5            1004      desktops                    1000    
2007     5            1000      computers                    0    


I need to create a hierarchy table based on info from the above table. I don't want to use self-join many times as I don't know how many layers there would be. I know an example from the book 'guru's guide to T-SQL' which can get close to what i want to get. The only difference is that I want to put different hierarchy in different column instead of indenting it. The code to do the hierarchy is somewhat like this:

INSERT staff VALUES (1,'GROUCHO',1)
INSERT staff VALUES (2,'CHICO',1)
INSERT staff VALUES (3,'HARPO',2)
INSERT staff VALUES (4,'ZEPPO',2)
INSERT staff VALUES (5,'MOE',1)
INSERT staff VALUES (6,'LARRY',5)
INSERT staff VALUES (7,'CURLY',5)
INSERT staff VALUES (8,'SHEMP',5)
INSERT staff VALUES (9,'JOE',8)
INSERT staff VALUES (10,'CURLY JOE',9)

SELECT seq=IDENTITY(int),
chartdepth=CASE WHEN o2.employee=o2.supervisor THEN 0 ELSE 1 END,
employee=o2.employee,
supervisor=o1.employee
INTO #org_chart
FROM staff o1 INNER JOIN staff o2 ON (o1.employee=o2.supervisor)
WHILE (@@rowcount > 0) BEGIN
INSERT #org_chart (chartdepth, employee, supervisor)
SELECT DISTINCT o1.chartdepth+1, o2.employee, o1.supervisor
FROM #org_chart o1 INNER JOIN #org_chart o2 ON (o1.employee=o2.supervisor)
WHERE o1.chartdepth=(SELECT MAX(chartdepth) FROM #org_chart)
AND o1.employee<>o1.supervisor
END
SELECT OrgChart=REPLICATE(CHAR(9),chartdepth)+s.employee_name
FROM (SELECT
employee,
seq=MIN(seq),
chartdepth=MAX(chartdepth)
FROM #org_chart
GROUP BY employee) o INNER JOIN staff s ON (o.employee=s.employee)
ORDER BY o.seq

If you run the above you would understand what I'm trying to get but i want the result look like this:        
level1                 level2              level3              level4              level5
GROUCHO         CHICO             HARPO
GROUCHO         CHICO             ZEPPO
GROUCHO         MOE                LARRY
GROUCHO         MOE               CURLY
GROUCHO         MOE               SHEMP             JOE                CURLY JOE

Thanks a lot for the help!
qinyanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

qinyanAuthor Commented:
sorry you need this part too:

CREATE TABLE staff (employee int PRIMARY KEY, employee_name varchar(10),
supervisor int NULL REFERENCES staff (employee))
0
Faiga DiegelSr Database EngineerCommented:
What version is your SQL? 2000 or 2005?
0
qinyanAuthor Commented:
2005
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.