title: More efficient SQL Server statement
body: <p>I'd like to know how I can increase the performance and efficiency of my SQL statement.
  Does anyone have some ideas or advices?</p>
  
  <pre><code>DECLARE @RoleName NVARCHAR(MAX)
  DECLARE @result INT
  
  SELECT @result = COUNT(DurchlaufVorgang.Durchlaufname)
  FROM   DurchlaufVorgang
  INNER JOIN RoleDepartment
          ON DurchlaufVorgang.AbteilungID = RoleDepartment.ID
  WHERE  DurchlaufVorgang.Depricated = 'FALSE'
         AND RoleDepartment.RoleName = @RoleName
         AND RoleDepartment.Depricated = 'FALSE'
  
  SELECT Antraege.AntragID
  FROM   ArtikelMitteilung,
         Antraege
  WHERE  ArtikelMitteilung.Status = 'Opened'
         AND Antraege.AntragID NOT IN 
            (SELECT Antraege.AntragID
             FROM   Vorgang,
                    Antraege
             WHERE  Vorgang.StepID IN 
                    (SELECT DurchlaufVorgang.ID
                     FROM   DurchlaufVorgang
                     INNER JOIN RoleDepartment
                             ON DurchlaufVorgang.AbteilungID = RoleDepartment.ID
                     WHERE DurchlaufVorgang.Depricated = 'FALSE'
                       AND RoleDepartment.RoleName = @RoleName
                       AND RoleDepartment.Depricated = 'FALSE')
                AND Vorgang.AntragsID = Antraege.ID
              GROUP  BY Antraege.AntragID
              HAVING COUNT(Antraege.AntragID) &gt;= @result)
         AND ArtikelMitteilung.AntragsID = Antraege.ID
  GROUP  BY Antraege.AntragID  
  </code></pre>
  
  <p>I'm grateful for your help.</p>