Skip to main content
Version: 8.3

QueryExtensions class

Level: advanced
note

The functionality is relevant to Classic UI.

The Terrasoft.Configuration.QueryExtensions utility class provides extending methods for the Terrasoft.Core.DB.Select class to build compact queries.

Each class method includes the sourceColumn parameter that can have the object types listed in the table below.

Type

Description

System.String

A column name in the TableAlias.ColumnName AS ColumnAlias format. Both TableAlias and ColumnAlias are optional. You can also pass "*" to select all columns.

Terrasoft.Core.DB.QueryColumnExpression

A query column expression that is added to the query without modification.

Terrasoft.Core.DB.IQueryColumnExpressionConvertible

An object that can be automatically converted to a QueryColumnExpression.

Terrasoft.Core.DB.Select

A subquery whose result can be used as a column in the main query.

If you pass an unsupported object type, Creatio throws an exception.

Methods

static Select Cols(
this Select select,
params object[] sourceColumns
)

Add specified columns or subexpressions to the query.

Parameters

select

The current Select instance to extend using additional columns.

sourceColumns

One or more columns or expressions to add to the query.

new Select(userConnection)
.Cols(
"L.Id",
"L.QualifyStatusId",
"L.LeadTypeId",
"L.LeadSourceId",
"L.LeadMediumId AS LeadChannel",
"L.BusinessPhone AS KnownBusinessPhone")
.From("Lead").As("L");

static Select Count(
this Select select,
object sourceColumn
)

Add an aggregation column to calculate the number of non-empty values in the query.

Parameters

select

The current Select instance to extend using the aggregation column.

sourceColumn

The column or expression for which non-empty values are calculated.

var activitiesCount = new Select(userConnection)
/* Specify the column name if needed. */
.Count("*")
.From("Activity")

static Select Coalesce(
this Select select,
params object[] sourceColumns
)

Add a column that determines the first non-NULL value in the query.

Parameters

select

The current Select instance to extend using a COALESCE column.

sourceColumns

One or more columns or expressions to evaluate in order.

new Select(userConnection)
.Cols("L.Id")
.Coalesce("L.CountryId", "C.CountryId", "A.CountryId")
.As("CountryId")
.From("Lead")
.As("L")
.LeftOuterJoin("Contact")
.As("C")
.On("L", "QualifiedContactId").IsEqual("C", "Id")
.LeftOuterJoin("Account")
.As("A")
.On("L", "QualifiedAccountId").IsEqual("A", "Id");

static Select DateDiff(
this Select select,
DateDiffQueryFunctionInterval interval,
object startDateExpression,
object endDateExpression
)

Add a column that specifies the date difference in the query.

Parameters

select

The current Select instance to extend using a DATEDIFF column.

interval

The unit of time to measure the difference, e. g., day, month, year.

startDateExpression

The column or expression that represents the starting date of the calculation.

endDateExpression

The column or expression that represents the ending date of the calculation.

var day = DateDiffQueryFunctionInterval.Day;

new Select(userConnection)
.Cols("L.Id")
.DateDiff(
day,
"L.CreatedOn",
Func.CurrentDateTime()
).As("LeadAge")
.From("Lead").As("L");

static Select IsNull(
this Select select,
object checkExpression,
object replacementValue
)

Add a column that replaces a NULL value with a replacement expression.

Parameters

select

The current Select instance to extend using an ISNULL column.

checkExpression

The column or expression to evaluate.

replacementValue

The value or expression used as a replacement when checkExpression is "NULL."

new Select(userConnection)
.Cols("L.Id")
.IsNull(
"L.CreatedOn",
"L.ModifiedOn"
)
.From("Lead").As("L");