Select T.*, P.Name As ProgramName, C.Name As ComponentName, S.Name As SubcomponentName
	Into ##Subcomponents
From
(
	Select '3cf41dc9-3c2a-41dd-9081-0df8ff3c59a6' As SubcomponentID Union
	Select '30e8c162-d0f2-49cc-8fed-9dbd9ee794de' As SubcomponentID 
) T
JOin dbo.BL_BudgetHierarchy S On T.SubcomponentID = S.ID
Join dbo.BL_BudgetHierarchy C On C.ID = S.ParentID
Join dbo.BL_BudgetHierarchy P On P.ID = C.ParentID




Select C.PurchaseTypeID 
From dbo.BL_Contracts C
Join ##Subcomponents S On C.BudgetHierarchyID = S.SubcomponentID