How to Calculate salary of employee

Analyst_SQL 3,551 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
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,948 questions
SQL Server Transact-SQL
SQL Server Transact-SQL
SQL Server: A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.Transact-SQL: A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
101 questions
0 comments No comments
{count} votes

Accepted answer
  1. Erland Sommarskog 112.6K Reputation points MVP
    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

0 additional answers

Sort by: Most helpful

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.