I d like to know how I can increase the performance and efficiency of my SQL statement. Does anyone have some ideas or advices?
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) >= @result)
AND ArtikelMitteilung.AntragsID = Antraege.ID
GROUP BY Antraege.AntragID
我感谢您的帮助。