title: Stored Procedure Error Incorrect Syntax Near 'end'
body: <p>I'm having a problem with this stored procedure, when I try to alter, I get this error:</p>
  <blockquote>
  <p>Msg 102, Level 15, State 1, Procedure PowerDMSADSynch, Line 73 [Batch Start Line 8]<br />
  Incorrect syntax near 'end'</p>
  </blockquote>
  <p>I'm not sure where to start troubleshooting, help is appreciated and code below:</p>
  <pre><code>SET ANSI_NULLS ON
  GO
  SET QUOTED_IDENTIFIER ON
  GO
  
  ALTER PROCEDURE [ads].[PowerDMSADSynch]
      @report varchar(50),
      @dmsgroup  varchar(50),
      @isactive varchar(50)
  AS
  BEGIN
      EXEC sp_refreshview 'ads.UsersActive';
      EXEC sp_refreshview 'ads.UsersInactive';
      EXEC sp_refreshview 'ads.Users';
      EXEC sp_refreshview 'ads.Groups';
  
      IF OBJECT_ID('tempdb..#groupInfo') IS NOT NULL
      BEGIN
          DROP TABLE #groupInfo; 
      END
  
      IF OBJECT_ID('tempdb..#userInfo') IS NOT NULL
      BEGIN
          DROP TABLE #userInfo; 
      END
  
      ;WITH groupInfo AS
      (
          SELECT sAMAccountName, distinguishedName, report = 'CHOMP Employees' 
          FROM ads.Groups 
          WHERE sAMAccountName = 'MH_PwrDMS_Users_CHOMP' 
  
          UNION
  
          SELECT sAMAccountName, distinguishedName, report = 'CHI Employees' 
          FROM ads.Groups 
          WHERE sAMAccountName = 'MH_PwrDMS_Users_CHI' 
  
          UNION
  
          SELECT sAMAccountName, distinguishedName, report = 'ASPIRE Employees' 
          FROM ads.Groups 
          WHERE sAMAccountName = 'MH_PwrDMS_Users_AHP' 
  
          UNION 
     
          SELECT sAMAccountName, distinguishedName, report = 'MoGo Employees' 
          FROM ads.Groups 
          WHERE sAMAccountName = 'MH_PwrDMS_Users_MoGo'
      )   
      SELECT *
      INTO #groupInfo
      FROM groupInfo;
  
      SELECT 
          U.sAMAccountName &quot;UserName&quot;, 
          U.sn &quot;LastName&quot;,
          U.givenName &quot;FirstName&quot;,
          U.middleName &quot;MiddleName&quot;,
          U.mail &quot;Email&quot;,
          U.departmentNumber &quot;Location&quot;,
          U.title &quot;JobTitle&quot;,
          'FALSE' &quot;Disabled&quot;,
          U.company &quot;Company&quot;,
          U.department &quot;Dept Name&quot;,
          U.employeeID &quot;Co + Dept Code&quot;,
          U.memberOf &quot;PDMS Group Membership&quot;,
          IsActive = CASE WHEN UI.AccountID IS NULL THEN 1 ELSE 0 END
      INTO #userInfo
      FROM ads.Users U
      LEFT JOIN ads.UsersInactive UI ON U.AccountID = UI.AccountID
      WHERE U.memberOf IS NOT NULL;
   
      SELECT GI.*, UI.*
      FROM #groupInfo GI
      INNER JOIN #userInfo UI ON UI.[PDMS Group Membership] LIKE CONCAT('%', GI.distinguishedName, '%')
      WHERE (@report IS NULL OR GI.report = @report)
        AND (@dmsgroup IS NULL OR GI.sAMAccountName = @dmsgroup)
        AND (@isactive = UI.IsActive);
  
      IF OBJECT_ID('tempdb..#groupInfo') IS NOT NULL
      BEGIN
          DROP TABLE #groupInfo; 
      END
  
      IF OBJECT_ID ('tempdb..#userInfo') IS NOT NULL
      BEGIN
          DROP TABLE #userInfo; 
      END
  </code></pre>