I notice you refer to catgeories in the SQL, but Category in the table listing - a typo there, somewhere?Hmm are you passing in parametre's? (show how you are calling the SP)Is there data?Here is a sample that works ... edit to add your necessary, and read the note! :)set nocount oncreate table Category ( CategoryID int, CategoryTypeID int)create table CategoryRelations ( RecordID int, ParentID int, ChildID int)goinsert into category select 1,1 --category 1, type 1unionselect 2,1 --category 2, type 1unionselect 3,1 --category 3, type 1unionselect 4,1 --category 4, type 1unionselect 5,1 --category 5, type 1unionselect 6,2 --category 6, type 2insert into CategoryRelationsselect 1,1,2 -- record1, which is parent 1, child 2unionselect 2,1,3 -- record2, which is parent 1, child 3unionselect 2,1,4 -- record2, which is parent 1, child 4unionselect 2,5,1 -- record2, which is parent 5, child 1unionselect 2,5,6 -- record2, which is parent 5, child 6goCREATE PROCEDURE spv_Products_GetCategoryRelations @CategoryID int,@CategoryTypeID intAS--note: I haven't added error handling (@@Error), or parametre checking (making sure you receive a value)--imho you should add these...select CR.ChildId --all childid'sfrom CategoryRelations CR inner join Category C on c.categoryid=cr.childidwhere cr.parentID = @categoryIDand c.CategoryTypeID = @CategoryTypeID--order by c.orderingNumber asc There is no ordering number in the example structure.order by CR.ChildIdgodeclare @CategoryID int, @CategoryTypeID intset @CategoryID = 1 --we want children of 1set @CategoryTypeID = 1 -- for categorytype 1exec spv_Products_GetCategoryRelations @CategoryID, @CategoryTypeIDdrop table categorydrop table CategoryRelationsdrop procedure spv_Products_GetCategoryRelations---results-- ChildId -- ----------- -- 2-- 3-- 4
*##* *##* *##* *##* Chaos, Disorder and Panic ... my work is done here!