Function to Calculate Body Mass Index in SQL Server

Hello to everyone,

In this article, I will talk about the function that calculates Body Mass Index in SQL Server. I felt the need to write because I could not find an article or example written on the subject. This is the first post in its field.

You may want to calculate body mass index in SQL Server.

First, let’s learn what the Body Mass Index.

Body mass index is calculated by dividing body mass by the square of the height in meters.

Function to Calculate Body Mass Index in SQL Server

So the algorithm is pretty simple.

You can easily do this with the help of the function below.

    @Weight FLOAT,
    @Height FLOAT
    DECLARE @VKI_Result INT = (@Weight / (@Height * @Height));
    DECLARE @Result NVARCHAR(20);
    IF @VKI_Result < 18
        SET @Result = N'Thin';
    ELSE IF (@VKI_Result >= 18 AND @VKI_Result < 25)
        SET @Result = N'Normal';
    ELSE IF (@VKI_Result >= 25 AND @VKI_Result < 30)
        SET @Result = N'Fat';
    ELSE IF (@VKI_Result >= 30 AND @VKI_Result < 35)
        SET @Result = N'Obese';
        SET @Result = N'Seriously Obese';
    RETURN @Result;


SELECT dbo.BMI_Calculate(100,1.80) AS Result


When you run the code you will get the following result.

Function to Calculate Body Mass Index in SQL Server

As you can see, he has calculated the Body Mass Index.

Good luck to everyone in business and life.


Yavuz Selim Kart

I try to explain what I know in software and database. I am still improving myself by doing research on many programming languages. Apart from these, I am also interested in Graphic Design and Wordpress. I also have knowledge about SEO and Social media management. In short, I am a determined person who likes to work hard.

You may also like...

Don`t copy text!