I am calculating the commission rate for employees and would like to sort the results by the total in descending order, but would also like to add the dollar sign in.
My current attempt is:
SELECT OrderLine.OrderID, Employee.FirstName AS "Employee First Name",
Employee.LastName AS "Employee Last Name",
'$' + CONVERT(NVARCHAR, SUM((CommissionRate * ((Quantity * Price) * (1 - Discount)))), 1) AS "Total Commission"
FROM OrderLine INNER JOIN [Order] ON Orderline.OrderID = [Order].OrderID
INNER JOIN Employee ON [Order].EmployeeID = Employee.EmployeeID
GROUP BY OrderLine.OrderID, Employee.FirstName, Employee.LastName
ORDER BY 'Total Commission' DESC
The output appears to be sorted as a string and my initial thought was to add:
ORDER BY SUM((CommissionRate * ((Quantity * Price) * (1 - Discount))))
But figured there was an easier way.
I had previously looked at the following questions on stack: