I have two tables
Employee
Finance
Employee contains 3 columns
Finance table contains 2 columns
I want to add TotalBonus column in Employee table. For calculation I am using BaseSalary from Employee table and BonusPercentage from Finance table.
TotalBonus = BaseSalary + (BaseSalary * BonusPercentage)
I can use this with stored procedure but i don't want. However, I created scalar function (calculateBonus) which returns TotalBonus but the problem is that i can't add column in table as i have dependency of BonusPercentage of Finance table.
In general i want employee table to have following:
I know there are many ways but want in Employee table as I am using this table on C#. Thanks
Assuming that there can be a maximum of one row in finance
for each employee, you want a (left) join:
SELECT e.id,
e.name,
e.basesalary,
coalesce(f.bonuspercentage, 0) * e.basesalary totalbonus
FROM employee e
LEFT JOIN finance f
ON f.id = e.id;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.