'How to calculate Body fat content in sql query

Formula

for Women (1.20 x BMI) + (0.23 x Age) - 5.4 for male (1.20 x BMI) + (0.23 x Age) - 16.2

I want to create an SQL query to calculate the Body fat content using the above formula. lets say BMI = 24 and age = 28



Solution 1:[1]

You could use a CASE for the conditional expression. For example, with a column named Gender:

SELECT
  CASE Gender 
     WHEN 'female' THEN (1.20 * BMI) + (0.23 * Age) - 5.4
     WHEN 'male'   THEN (1.20 * BMI) + (0.23 * Age) - 16.2
  END
FROM dbo.YourTable;

Solution 2:[2]

Did you wanted to put it in a select? If so you could just use this:

((1.20 x BMI) + (0.23 x Age)) - (5.4 for male (1.20 x BMI) + (0.23 x Age) - 16.2) AS WOMEN_BODY_FAT

Your BMI and AGE will also getting value automatically if there are containt in the table WOMAN.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Olivier Jacot-Descombes
Solution 2 Xavier Blouin