Hi!
IMHO the easiest way add column to your table (or if it's impossible create temp table), which would describe full path to your item at the hierarchy.
All Table ... Add ItemPath varchar(...)
1, NULL, Books, '.1.'
2, 1, Computers, '.1.2.'
3, 2, Programming, '.1.2.3.'
4, 3, T_SQL...