Reference > Functions > String
Soundex
- 2005
- 2008
- 2012
- 2014
- 2016
- 2017
- 2019
- 2022
- 2005, 2008, 2012, 2014, 2016, 2017, 2019, 2022
Soundex String Function
Use the Soundex
function to evaluate the similarity of two strings.
Syntax
db.fx.Soundex({expression})
Arguments
- expression
- – The value to use for computation of the four character result.
Returns
string or string?
(depending on the nullability of `expression`)
Examples
Select Statement
Select the soundex value of a person's last name.
IEnumerable<string> result = db.SelectMany(
db.fx.Soundex(dbo.Person.LastName)
)
.From(dbo.Person)
.Execute();
Where Clause
Select persons where their last name is similar to their first name.
IEnumerable<Person> result = db.SelectMany<Person>()
.From(dbo.Person)
.Where(db.fx.Soundex(dbo.Person.LastName) != dbo.Person.LastName)
.Execute();
Order By Clause
Select a list of persons, ordered by the soundex value of their last name.
IEnumerable<Person> result = db.SelectMany<Person>()
.From(dbo.Person)
.OrderBy(db.fx.Soundex(dbo.Person.LastName))
.Execute();
Group By Clause
Select a list of address values grouped by address type and the similarity of the names of the city they live in (distinct list of similar sonding cities).
IEnumerable<dynamic> values = db.SelectMany(
dbo.Address.AddressType,
db.fx.Soundex(dbo.Address.City).As("city")
)
.From(dbo.Address)
.GroupBy(
dbo.Address.AddressType,
db.fx.Soundex(dbo.Address.City)
)
.Execute();
Having Clause
Select a list of address data, grouped by address type and city where the value of city with leading and 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.Soundex(dbo.Address.City) == "G452"
)
.Execute();