Assuming the mistakes in your data are just typos in the question,
Grouping Sets[
^] will do what you want.
WITH cteData As
(
SELECT
L.Location,
D.Department,
S.Salary
FROM
Location As L
INNER JOIN Department As D
ON D.ID = L.ID
INNER JOIN Salary As S
ON S.ID = L.ID
)
SELECT
Location,
CASE
WHEN Location Is Null THEN 'Total Salary'
WHEN Department Is Null THEN 'Salary'
ELSE Department
END As Department,
Sum(Salary) As Salary
FROM
cteData
GROUP BY GROUPING SETS
(
(Location, Department),
(Location),
()
);
Output:
Location Department Salary
L1 D1 1000
L1 D2 2000
L1 Salary 3000
L2 D3 1500
L2 D4 2000
L2 Salary 3500
NULL Total Salary 6500
Any further formatting needs to be done in the UI.