Reference > Functions > Mathematical
Square
- 2005
- 2008
- 2012
- 2014
- 2016
- 2017
- 2019
- 2022
- 2005, 2008, 2012, 2014, 2016, 2017, 2019, 2022
Square Mathematical Function
Use the Square
function to return the square of the specified expression (value raised to the power of 2 n^2
).
Syntax
db.fx.Square({expression})
Arguments
- expression
- – The value to square.
Returns
float
Examples
Select Statement
Select the square of a product's height (which is nullable in the database).
float? result = db.SelectOne(
db.fx.Square(dbo.Product.Height)
)
.From(dbo.Product)
.Execute();
Where Clause
Select a list of product ids where the square of the product's depth is greater than 0 and less than 1.
IEnumerable<int> results = db.SelectMany(
dbo.Product.Id
)
.From(dbo.Product)
.Where(db.fx.Square(dbo.Product.Depth) > 0 & db.fx.Square(dbo.Product.Depth) < 1)
.Execute();
Order By Clause
Select and order by the square of a product's depth.
IEnumerable<Product> result = db.SelectMany<Product>()
.From(dbo.Product)
.OrderBy(db.fx.Square(dbo.Product.Depth).Desc())
.Execute();
Group By Clause
Select product details grouped by product category and square of the product's depth.
IEnumerable<dynamic> results = db.SelectMany(
dbo.Product.ProductCategoryType,
db.fx.Square(dbo.Product.Depth).As("calculated_value")
)
.From(dbo.Product)
.GroupBy(
dbo.Product.ProductCategoryType,
db.fx.Square(dbo.Product.Depth)
)
.Execute();
Having Clause
Select the ids of all products, grouped by product category type having an square 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.Square(dbo.Product.Height)
)
.Having(
db.fx.Square(dbo.Product.Height) < .5f
)
.Execute();