Reference > Functions > Mathematical

Ceiling

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

Ceiling Mathematical Function

Use the Ceiling function to returns the smallest integer value greater than or equal to the specified expression.

Syntax

db.fx.Ceiling({expression})

Arguments

expression
The value to use in the ceiling calculation.

Returns

The same type as `expression`.

Examples

Select Statement

Select the ceiling of total purchase amount for all purchases.

IEnumerable<double> value = db.SelectMany(
        db.fx.Ceiling(dbo.Purchase.TotalPurchaseAmount)
    )
    .From(dbo.Purchase)
    .Execute();

Where Clause

Select all purchase ids where the ceiling of total purchase amount is less than or equal to 100.

IEnumerable<int> value = db.SelectMany(
        dbo.Purchase.Id
    )
    .From(dbo.Purchase)
    .Where(db.fx.Ceiling(dbo.Purchase.TotalPurchaseAmount) <= 100)
    .Execute();

Order By Clause

Select the ceiling value of total purchase amount for all purchases ordered by the ceiling value descending.

IEnumerable<double> value = db.SelectMany(
        dbo.Purchase.TotalPurchaseAmount
    )
    .From(dbo.Purchase)
    .OrderBy(db.fx.Ceiling(dbo.Purchase.TotalPurchaseAmount).Desc())
    .Execute();

Group By Clause

Select the payment method and ceiling of total purchase amount for all purchases, grouped by payment method type and ordered by the ceiling of total purchase amount.

IEnumerable<dynamic> values = db.SelectMany(
        dbo.Purchase.PaymentMethodType,
        db.fx.Ceiling(dbo.Purchase.TotalPurchaseAmount).As("TotalPurchaseAmount")
    )
    .From(dbo.Purchase)
    .GroupBy(
        dbo.Purchase.PaymentMethodType,
        db.fx.Ceiling(dbo.Purchase.TotalPurchaseAmount)
    )
    .OrderBy(db.fx.Ceiling(dbo.Purchase.TotalPurchaseAmount))
    .Execute();

Having Clause

Select the payment method and absolute value of total purchase amount for all purchases, grouped by payment method type having an absolute value greater than 10 and ordered by the absolute value of total purchase amount.

IEnumerable<dynamic> values = db.SelectMany(
        dbo.Purchase.PaymentMethodType,
        db.fx.Ceiling(dbo.Purchase.TotalPurchaseAmount).As("TotalPurchaseAmount")
    )
    .From(dbo.Purchase)
    .GroupBy(
        dbo.Purchase.PaymentMethodType,
        db.fx.Ceiling(dbo.Purchase.TotalPurchaseAmount)
    )
    .Having(db.fx.Ceiling(dbo.Purchase.TotalPurchaseAmount) > 10)
    .OrderBy(db.fx.Ceiling(dbo.Purchase.TotalPurchaseAmount))
    .Execute();
Previous
ATan

© 2024 dbExpression. All rights reserved.