



CREATE PROCEDURE DBO.AllUplinksAgency AS
SET NOCOUNT ON

  Insert #TempTab(CustomerNumber,CustomerTypeNumber,ProcessingNumber) --finder alle sales channel der er linket til agencycorp
  Select CustomerNumber,CustomerTypeNumber,1 from Customer WITH (NOLOCK) where CustomerTypeNumber=7  And CustomerNumber In
 (Select CustomerNumber from CustomerLinks WITH (NOLOCK) where LinkTypeNumber=0 and CustomerLinkNumber in (select CustomerNumber from #FoundValues where CustomerTypeNumber=5 ) UNION ALL
  Select CustomerLinkNumber from CustomerLinks WITH (NOLOCK) where LinkTypeNumber=0 and CustomerNumber in  (select CustomerNumber from #FoundValues where CustomerTypeNumber=5 ))

