Try this:
SELECT SUM(COALESCE(BSE.MinWageEarning, BSE.TotalBeforeMinWage)) - SUM(BSE.TotalBeforeMinWage) AS Bonus
FROM vBookingSessionEmployees AS BSE
...
For further details, please see:
COALESCE (Transact-SQL) - SQL Server | Microsoft Docs[
^]
ISNULL (Transact-SQL) - SQL Server | Microsoft Docs[
^]
Note: use
aliases[
^]!
Will Sewell wrote:
Thank you for the answer but this seems to return the same result as the code I was using.
You're wrong!
If you don't believe me, check this out:
CREATE TABLE SomeData
(
A DECIMAL(8,2),
B DECIMAL(8,2)
);
INSERT INTO SomeData(A, B)
VALUES(NULL, 2.45),
(24.08, 8.00),
(NULL, 0.69);
SELECT COALESCE(A, B) - B AS Total
FROM SomeData;
SELECT ISNULL(A, 0) - B AS Total
FROM SomeData;
Results:
#1)
Total
0.00
16.08
0.00
#2)
-2.45
16.08
-0.69
SQL Server 2019 | db<>fiddle[
^]