Reference > Functions > Mathematical

Sqrt

  • 2005, 2008, 2012, 2014, 2016, 2017, 2019, 2022

Sqrt (Square Root) Mathematical Function

Use the Sqrt function to return the square root of the specified expression.

Syntax

db.fx.Sqrt({expression})

Arguments

expression
The value to use in the square root calculation.

Returns

float

Examples

Select Statement

Select the square root of a product's height (which is nullable in the database).

float? result = db.SelectOne(
        db.fx.Sqrt(dbo.Product.Height)
    )
    .From(dbo.Product)
    .Execute();

Where Clause

Select the square root of a product's depth (which is nullable in the database) where the product's depth is greater than 0 and less than 10.

float? result = db.SelectOne(
        db.fx.Sqrt(dbo.Product.Depth)
    )
    .From(dbo.Product)
    .Where(dbo.Product.Depth > 0 & dbo.Product.Depth < 10)
    .Execute();

Order By Clause

Select and order by the square root of a product's depth.

IEnumerable<Product> result = db.SelectMany<Product>()
    .From(dbo.Product)
    .OrderBy(db.fx.Sqrt(dbo.Product.Depth).Desc())
    .Execute();

Group By Clause

Select product details grouped by product category and square root of the product's depth.

IEnumerable<dynamic> results = db.SelectMany(
        dbo.Product.ProductCategoryType,
        db.fx.Sqrt(dbo.Product.Depth).As("calculated_value")
    )
    .From(dbo.Product)
    .GroupBy(
        dbo.Product.ProductCategoryType,
        db.fx.Sqrt(dbo.Product.Depth)
    )
    .Execute();

Having Clause

Select the ids of all products, grouped by product category type having an square root of the product's height greater than 1.

IEnumerable<ProductCategoryType?> results = db.SelectMany(
        dbo.Product.ProductCategoryType
    )
    .From(dbo.Product)
    .GroupBy(
        dbo.Product.ProductCategoryType,
        db.fx.Sqrt(dbo.Product.Height)
    )
    .Having(
        db.fx.Sqrt(dbo.Product.Height) < .5f
    )
    .Execute();
Previous
Sin

© 2024 dbExpression. All rights reserved.