Subquery SELECT COUNTs
SELECT
(SELECT COUNT(*)
From dbo.OdsBuild AS P
where P.StartTime Between @StartDate and @EndDate
AND P.Official = 1) totalItems ,
(SELECT COUNT(*)
From dbo.Items AS P
where p.StartTime Between @StartDate and @EndDate
AND P.Official = 1 AND ( P.Result = 7 OR P.Result = 8 OR P.Result = 14)) failedItems
If you have already set them as variables, of course, you do not need to repeat SELECT COUNT.
SELECT @totalItems AS totalItems, @failedItems AS failedItems
SELECT statements allow autonomously without FROM clauses.
source
share