I'm having trouble with the following IF... ELSE statement.I would have thought that in the script below only the first IF section should be executed because the @LegalEntityGroup is not null. However, this is not the case. It seems that all three IF sections are executed. I get the following error message...Msg 2714, Level 16, State 1, Line 28There is already an object named '#LegalEntities' in the database.Msg 2714, Level 16, State 1, Line 35There is already an object named '#LegalEntities' in the database.DECLARE @LegalEntityGroup varchar(4000)DECLARE @LegalEntity varchar(4000)SET @LegalEntityGroup = 'All HF Accounts'SET @LegalEntity = NULL-- Populate a table listing all the legal entities to search forIF object_id('tempdb..#LegalEntities') IS NOT NULL DROP TABLE #LegalEntitiesIF @LegalEntityGroup IS NOT NULL BEGIN SELECT LegalEntity INTO #LegalEntities FROM [config].[LegalEntityGroupMember] WHERE [Group] IN (SELECT * FROM config.fnSplit(@LegalEntityGroup, ',')) ENDELSE BEGIN IF @LegalEntity IS NOT NULL BEGIN SELECT LegalEntity INTO #LegalEntities FROM [config].[LegalEntity] WHERE LegalEntity IN (SELECT * FROM config.fnSplit(@LegalEntity, ',')) END ELSE BEGIN SELECT LegalEntity INTO #LegalEntities FROM config.fnUserLegalEntities(1,NULL) END ENDCan anyone help me out with this?