			CREATE PROCEDURE DBO.AllDownLinksCompany AS
SET NOCOUNT ON

Insert #FoundValues(CustomerNumber,CustomerTypeNumber)
  select CustomerNumber,CustomerTypeNumber from Customer WITH (NOLOCK) where CustomerTypeNumber=1 and CustomerNumber in
  (Select CustomerNumber from CustomerLinks WITH (NOLOCK) where LinkTypeNumber=0 and CustomerLinkNumber in (select  CustomerNumber from #FoundValues where CustomerTypeNumber=2 ) UNION ALL
  Select CustomerLinkNumber from CustomerLinks WITH (NOLOCK) where LinkTypeNumber=0 and  CustomerNumber in  (select  CustomerNumber from #FoundValues where CustomerTypeNumber=2))

