



CREATE PROCEDURE DBO.FindValues @CustomerNumber int,@CustomerTypeNumber SmallInt AS
SET NOCOUNT ON
Insert #FoundValues(CustomerNumber,CustomerTypeNumber)
  select CustomerNumber,CustomerTypeNumber from Customer WITH (NOLOCK) where CustomerTypeNumber=@CustomerTypeNumber and CustomerNumber in
  (Select CustomerNumber from CustomerLinks WITH (NOLOCK) where LinkTypeNumber=0 and CustomerLinkNumber=@CustomerNumber UNION ALL
  Select CustomerLinkNumber from CustomerLinks WITH (NOLOCK) where LinkTypeNumber=0 and  CustomerNumber=@CustomerNumber)

