I've got to total 3 counters. I've got 2 solutions to get the counts. Without comparing execution plans and empirical mesurement, any thoughts on which is the better approach?Solution 1SELECT @BranchUSRTotal = COUNT(*) FROM dbo.Users U WHERE @BranchID IS NOT NULL AND U.BranchID = @BranchID -- No need to test ClientID for specific BranchID AND U.Inactive = 1 -- Active Users OnlySELECT @CenterUSRTotal = COUNT(*) FROM dbo.Users U WHERE @CenterID IS NOT NULL AND U.CenterID = @CenterID AND U.Inactive = 1SELECT @ClientUSRTotal = COUNT(*) FROM dbo.Users U WHERE U.ClientID = @ClientID AND U.Inactive = 1
Solution 2SELECT @ClientUSRTotal = COUNT(*) , @CenterUSRTotal = SUM(CASE WHEN U.CenterID = @CenterID THEN 1 ELSE 0 END) , @BranchUSRTotal = SUM(CASE WHEN U.BranchID = @BranchID THEN 1 ELSE 0 END) FROM dbo.Users U WHERE U.ClientID = @ClientID AND U.Inactive = 1