Reference > Functions > String

RTrim

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

RTrim (Right Trim) String Function

Use the RTrim function to remove trailing spaces from a string expression.

Syntax

db.fx.RTrim({expression})

Arguments

expression
The value to remove trailing spaces from.

Returns

string or string?
(depending on the nullability of `expression`)

Examples

Select Statement

Select the a person's last name, with trailing spaces removed.

IEnumerable<string> result = db.SelectMany(
		db.fx.RTrim(dbo.Person.LastName)
	)
	.From(dbo.Person)
	.Execute();

Where Clause

Select persons where their last name ends with one or more spaces.

IEnumerable<Person> result = db.SelectMany<Person>()
    .From(dbo.Person)
	.Where(db.fx.RTrim(dbo.Person.LastName) != dbo.Person.LastName)
	.Execute();

Order By Clause

Select a list of persons, ordered by their last name with trailing spaces removed.

IEnumerable<Person> result = db.SelectMany<Person>()
	.From(dbo.Person)
	.OrderBy(db.fx.RTrim(dbo.Person.LastName))
	.Execute();

Group By Clause

Select a list of address values grouped by address type and the value of the city field with trailing spaces removed.

IEnumerable<dynamic> values = db.SelectMany(
		dbo.Address.AddressType,
		db.fx.RTrim(dbo.Address.City).As("city")
	)
	.From(dbo.Address)
	.GroupBy(
		dbo.Address.AddressType,
		db.fx.RTrim(dbo.Address.City)
	)
	.Execute();

Having Clause

Select a list of address data, grouped by address type and city where the value of city with trailing spaces removed is "Chicago".

IEnumerable<dynamic> addresses = db.SelectMany(
		db.fx.Count().As("count"),
		dbo.Address.AddressType
	)
	.From(dbo.Address)
	.GroupBy(
		dbo.Address.AddressType,
		dbo.Address.City
	)
	.Having(
		db.fx.RTrim(dbo.Address.City) == "Los Angeles"
	)
	.Execute();
Previous
Right

© 2024 dbExpression. All rights reserved.