How to Calculate salary of employee

Analyst_SQL 3,576 Reputation points
2024-04-27T06:08:58.23+00:00

I am calculating salary using below query

SELECT '29' as Total_Days,'28' as Present_Days,
    (14000 / 29) AS Per_Day,
    (14000 / 29) * 28 AS Total_Salary;


User's image

But Total_Salary should be 14000 because Total_Days 29 and Present_Day 29

SQL Server | SQL Server Transact-SQL
SQL Server | Other
0 comments No comments
{count} votes

Accepted answer
  1. Erland Sommarskog 124.9K Reputation points MVP Volunteer Moderator
    2024-04-27T10:03:14.1233333+00:00

    Well, multiply by 29 rather than 28 then.

    But keep in mind that when you divide two integers you get integer division. That is the result of 14000 / 29 is 482 sharp, not 482 comma something. To get a division which includes the remnant, you need to cast at least one of the operands to a data type that handles decimals, for instance decimal or float.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.