Reference > Functions > String
Right
- 2005
- 2008
- 2012
- 2014
- 2016
- 2017
- 2019
- 2022
- 2005, 2008, 2012, 2014, 2016, 2017, 2019, 2022
Right String Function
Use the Right
function to return the end of a string with the specified number of characters.
Syntax
db.fx.Right({expression}, {character_count})
Arguments
- expression
- – The value to take trailing characters from.
- character_count
- – The number of characters to take from the end of `expression`.
Returns
string or string?
(depending on the nullability of `expression` and `character_count`)
Examples
Select Statement
Select the last letter of city
IEnumerable<string> result = db.SelectMany(
db.fx.Right(dbo.Address.City, 1)
)
.From(dbo.Address)
.Execute();
Where Clause
Select address ids where the city name ends with "ly"
IEnumerable<int> result = db.SelectMany(
dbo.Address.Id
)
.From(dbo.Address)
.Where(db.fx.Right(dbo.Address.City, 2) == "ly")
.Execute();
Order By Clause
Select a list of persons, ordered by the last character of their first name.
IEnumerable<Person> persons = db.SelectMany<Person>()
.From(dbo.Person)
.OrderBy(
db.fx.Right(dbo.Person.FirstName, 1)
)
.Execute();
Group By Clause
Select a list of data for persons, grouped by the initial of their last name.
IEnumerable<dynamic> values = db.SelectMany(
db.fx.Count().As("count"),
dbo.Person.YearOfLastCreditLimitReview,
db.fx.Right(dbo.Person.LastName, 1).As("last_character")
)
.From(dbo.Person)
.GroupBy(
dbo.Person.YearOfLastCreditLimitReview,
db.fx.Right(dbo.Person.LastName, 1)
)
.Execute();
Having Clause
Select a list of data for persons, grouped by the last character of their last name having a last character equal to ".".
IEnumerable<dynamic> addresses = db.SelectMany(
db.fx.Count().As("count"),
dbo.Person.YearOfLastCreditLimitReview,
db.fx.Right(dbo.Person.LastName, 1).As("last_character")
)
.From(dbo.Person)
.GroupBy(
dbo.Person.YearOfLastCreditLimitReview,
db.fx.Right(dbo.Person.LastName, 1)
)
.Having(
db.fx.Right(dbo.Person.LastName, 1) > "."
)
.Execute();