Table of Contents

Class SqlFn

Namespace
LinqToDB.DataProvider.SqlServer
Assembly
linq2db.dll
public static class SqlFn
Inheritance
SqlFn

Properties

Connections

@@CONNECTIONS (Transact-SQL)

This function returns the number of attempted connections - both successful and unsuccessful - since SQL Server was last started.

[Sql.Expression("SqlServer", "@@CONNECTIONS", ServerSideOnly = true)]
public static int Connections { get; }

Property Value

int

integer

Exceptions

InvalidOperationException

CpuBusy

@@CPU_BUSY (Transact-SQL)

This function returns the amount of time that SQL Server has spent in active operation since its latest start.

[Sql.Expression("SqlServer", "@@CPU_BUSY", ServerSideOnly = true)]
public static int CpuBusy { get; }

Property Value

int

integer

Exceptions

InvalidOperationException

CurrentTimestamp

CURRENT_TIMESTAMP (Transact-SQL)

This function returns the current database system timestamp as a datetime value, without the database time zone offset. CURRENT_TIMESTAMP derives this value from the operating system of the computer on which the instance of SQL Server runs.

[Sql.Expression("SqlServer", "CURRENT_TIMESTAMP", ServerSideOnly = true, IgnoreGenericParameters = true)]
public static DateTime CurrentTimestamp { get; }

Property Value

DateTime

datetime

Exceptions

InvalidOperationException

DateFirst

@@DATEFIRST (Transact-SQL)

This function returns the current value of SET DATEFIRST, for a specific session.

[Sql.Expression("SqlServer", "@@DATEFIRST", ServerSideOnly = true, IgnoreGenericParameters = true)]
public static byte DateFirst { get; }

Property Value

byte

tinyint

Exceptions

InvalidOperationException

DbTS

@@DBTS (Transact-SQL)

This function returns the value of the current timestamp data type for the current database. The current database will have a guaranteed unique timestamp value.

[Sql.Expression("SqlServer", "@@DBTS", ServerSideOnly = true)]
public static byte[] DbTS { get; }

Property Value

byte[]

varbinary

Exceptions

InvalidOperationException

IOBusy

@@IO_BUSY (Transact-SQL)

Returns the time that SQL Server has spent performing input and output operations since SQL Server was last started.

[Sql.Expression("SqlServer", "@@IO_BUSY", ServerSideOnly = true)]
public static int IOBusy { get; }

Property Value

int

integer

Exceptions

InvalidOperationException

Identity

@@IDENTITY (Transact-SQL)

Is a system function that returns the last-inserted identity value.

[Sql.Expression("SqlServer", "@@IDENTITY", ServerSideOnly = true)]
public static decimal? Identity { get; }

Property Value

decimal?

numeric(38,0)

Exceptions

InvalidOperationException

Idle

@@IDLE (Transact-SQL)

Returns the time that SQL Server has been idle since it was last started.

[Sql.Expression("SqlServer", "@@IDLE", ServerSideOnly = true)]
public static int Idle { get; }

Property Value

int

integer

Exceptions

InvalidOperationException

LangID

@@LANGID (Transact-SQL)

Returns the local language identifier (ID) of the language that is currently being used.

[Sql.Expression("SqlServer", "@@LANGID", ServerSideOnly = true)]
public static short LangID { get; }

Property Value

short

smallint

Exceptions

InvalidOperationException

Language

@@LANGUAGE (Transact-SQL)

Returns the name of the language currently being used.

[Sql.Expression("SqlServer", "@@LANGUAGE", ServerSideOnly = true)]
public static string Language { get; }

Property Value

string

nvarchar

Exceptions

InvalidOperationException

LockTimeout

@@LOCK_TIMEOUT (Transact-SQL)

Returns the current lock time-out setting in milliseconds for the current session.

[Sql.Expression("SqlServer", "@@LOCK_TIMEOUT", ServerSideOnly = true)]
public static int LockTimeout { get; }

Property Value

int

integer

Exceptions

InvalidOperationException

MaxConnections

@@MAX_CONNECTIONS (Transact-SQL)

Returns the maximum number of simultaneous user connections allowed on an instance of SQL Server. The number returned is not necessarily the number currently configured.

[Sql.Expression("SqlServer", "@@MAX_CONNECTIONS", ServerSideOnly = true)]
public static int MaxConnections { get; }

Property Value

int

integer

Exceptions

InvalidOperationException

MaxPrecision

@@MAX_PRECISION (Transact-SQL)

Returns the precision level used by decimal and numeric data types as currently set in the server.

[CLSCompliant(false)]
[Sql.Expression("SqlServer", "@@MAX_PRECISION", ServerSideOnly = true)]
public static byte MaxPrecision { get; }

Property Value

byte

tinyint

Exceptions

InvalidOperationException

NestLevel

@@NESTLEVEL (Transact-SQL)

Returns the nesting level of the current stored procedure execution (initially 0) on the local server.

[Sql.Expression("SqlServer", "@@NESTLEVEL", ServerSideOnly = true)]
[CLSCompliant(false)]
public static int NestLevel { get; }

Property Value

int

int

Exceptions

InvalidOperationException

Options

@@OPTIONS (Transact-SQL)

Returns information about the current SET options.

[Sql.Expression("SqlServer", "@@OPTIONS", ServerSideOnly = true)]
public static int Options { get; }

Property Value

int

integer

Exceptions

InvalidOperationException

PackReceived

@@PACK_RECEIVED (Transact-SQL)

Returns the number of input packets read from the network by SQL Server since it was last started.

[Sql.Expression("SqlServer", "@@PACK_RECEIVED", ServerSideOnly = true)]
public static int PackReceived { get; }

Property Value

int

integer

Exceptions

InvalidOperationException

PackSent

@@PACK_SENT (Transact-SQL)

Returns the number of output packets written to the network by SQL Server since it was last started.

[Sql.Expression("SqlServer", "@@PACK_SENT", ServerSideOnly = true)]
public static int PackSent { get; }

Property Value

int

integer

Exceptions

InvalidOperationException

PacketErrors

@@PACKET_ERRORS (Transact-SQL)

Returns the number of network packet errors that have occurred on SQL Server connections since SQL Server was last started.

[Sql.Expression("SqlServer", "@@PACKET_ERRORS", ServerSideOnly = true)]
public static int PacketErrors { get; }

Property Value

int

integer

Exceptions

InvalidOperationException

RemServer

@@REMSERVER (Transact-SQL)

Returns the name of the remote SQL Server database server as it appears in the login record.

[Sql.Expression("SqlServer", "@@REMSERVER", ServerSideOnly = true)]
public static string? RemServer { get; }

Property Value

string

nvarchar(128)

Exceptions

InvalidOperationException

RowCount

@@ROWCOUNT (Transact-SQL)

Returns the number of rows affected by the last statement. If the number of rows is more than 2 billion, use ROWCOUNT_BIG.

[Sql.Expression("SqlServer", "@@ROWCOUNT", ServerSideOnly = true)]
public static int RowCount { get; }

Property Value

int

int

Exceptions

InvalidOperationException

ServerName

@@SERVERNAME (Transact-SQL)

Returns the name of the local server that is running SQL Server.

[Sql.Expression("SqlServer", "@@SERVERNAME", ServerSideOnly = true)]
public static string ServerName { get; }

Property Value

string

nvarchar

Exceptions

InvalidOperationException

ServiceName

@@SERVICENAME (Transact-SQL)

Returns the name of the registry key under which SQL Server is running. @@SERVICENAME returns 'MSSQLSERVER' if the current instance is the default instance; this function returns the instance name if the current instance is a named instance.

[Sql.Expression("SqlServer", "@@SERVICENAME", ServerSideOnly = true)]
public static string ServiceName { get; }

Property Value

string

nvarchar

Exceptions

InvalidOperationException

SpID

@@SPID (Transact-SQL)

Returns the session ID of the current user process.

[Sql.Expression("SqlServer", "@@SPID", ServerSideOnly = true)]
public static short SpID { get; }

Property Value

short

smallint

Exceptions

InvalidOperationException

TextSize

@@TEXTSIZE (Transact-SQL)

Returns the current value of the TEXTSIZE option.

[Sql.Expression("SqlServer", "@@TEXTSIZE", ServerSideOnly = true)]
public static int TextSize { get; }

Property Value

int

integer

Exceptions

InvalidOperationException

TimeTicks

@@TIMETICKS (Transact-SQL)

Returns the number of microseconds per tick.

[Sql.Expression("SqlServer", "@@TIMETICKS", ServerSideOnly = true)]
public static int TimeTicks { get; }

Property Value

int

integer

Exceptions

InvalidOperationException

TotalErrors

@@TOTAL_ERRORS (Transact-SQL)

Returns the number of microseconds per tick.

[Sql.Expression("SqlServer", "@@TOTAL_ERRORS", ServerSideOnly = true)]
public static int TotalErrors { get; }

Property Value

int

integer

Exceptions

InvalidOperationException

TotalRead

@@TOTAL_READ (Transact-SQL)

Returns the number of microseconds per tick.

[Sql.Expression("SqlServer", "@@TOTAL_READ", ServerSideOnly = true)]
public static int TotalRead { get; }

Property Value

int

integer

Exceptions

InvalidOperationException

TotalWrite

@@TOTAL_WRITE (Transact-SQL)

Returns the number of microseconds per tick.

[Sql.Expression("SqlServer", "@@TOTAL_WRITE", ServerSideOnly = true)]
public static int TotalWrite { get; }

Property Value

int

integer

Exceptions

InvalidOperationException

TransactionCount

@@TRANCOUNT (Transact-SQL)

Returns the number of input packets read from the network by SQL Server since it was last started.

[Sql.Expression("SqlServer", "@@TRANCOUNT", ServerSideOnly = true)]
public static int TransactionCount { get; }

Property Value

int

integer

Exceptions

InvalidOperationException

Version

@@VERSION (Transact-SQL)

Returns system and build information for the current installation of SQL Server.

[Sql.Expression("SqlServer", "@@VERSION", ServerSideOnly = true)]
public static string Version { get; }

Property Value

string

nvarchar

Exceptions

InvalidOperationException

Methods

Abs<T>(T)

ABS (Transact-SQL)

A mathematical function that returns the absolute (positive) value of the specified numeric expression. (ABS changes negative values to positive values. ABS has no effect on zero or positive values.)

[Sql.Function("SqlServer", "ABS", ServerSideOnly = true, IgnoreGenericParameters = true)]
public static T Abs<T>(T numeric_expression)

Parameters

numeric_expression T

An expression of the exact numeric or approximate numeric data type category.

Returns

T

Returns the same type as numeric_expression.

Type Parameters

T

Exceptions

InvalidOperationException

Acos<T>(T)

ACOS (Transact-SQL)

A function that returns the angle, in radians, whose cosine is the specified float expression. This is also called arccosine.

[Sql.Function("SqlServer", "ACOS", ServerSideOnly = true, IgnoreGenericParameters = true)]
public static T Acos<T>(T float_expression)

Parameters

float_expression T

An expression of either type float or of a type that can implicitly convert to float. Only a value ranging from -1.00 to 1.00 is valid. For values outside this range, no value is returned, and ACOS will report a domain error.

Returns

T

float

Type Parameters

T

Exceptions

InvalidOperationException

AppName()

APP_NAME (Transact-SQL)

This function returns the application name for the current session, if the application sets that name value.

[Sql.Function("SqlServer", "APP_NAME", ServerSideOnly = true)]
public static string AppName()

Returns

string

nvarchar(128)

Exceptions

InvalidOperationException

Ascii(char)

ASCII (Transact-SQL)

Returns the ASCII code value of the leftmost character of a character expression.

[Sql.Function("SqlServer", "ASCII", ServerSideOnly = true)]
public static int Ascii(char character_expression)

Parameters

character_expression char

An expression of type char or varchar.

Returns

int

int

Exceptions

InvalidOperationException

Ascii(string?)

ASCII (Transact-SQL)

Returns the ASCII code value of the leftmost character of a character expression.

[Sql.Function("SqlServer", "ASCII", ServerSideOnly = true)]
public static int? Ascii(string? character_expression)

Parameters

character_expression string

An expression of type char or varchar.

Returns

int?

int

Exceptions

InvalidOperationException

Asin<T>(T)

ASIN (Transact-SQL)

A function that returns the angle, in radians, whose sine is the specified float expression. This is also called arcsine.

[Sql.Function("SqlServer", "ASIN", ServerSideOnly = true, IgnoreGenericParameters = true)]
public static T Asin<T>(T float_expression)

Parameters

float_expression T

An expression of either type float or of a type that can implicitly convert to float. Only a value ranging from -1.00 to 1.00 is valid. For values outside this range, no value is returned, and ASIN will report a domain error.

Returns

T

float

Type Parameters

T

Exceptions

InvalidOperationException

Atan<T>(T)

ATAN (Transact-SQL)

A function that returns the angle, in radians, whose tangent is a specified float expression. This is also called arctangent.

[Sql.Function("SqlServer", "ATAN", ServerSideOnly = true, IgnoreGenericParameters = true)]
public static T Atan<T>(T float_expression)

Parameters

float_expression T

An expression of either type float or of a type that implicitly convert to float.

Returns

T

float

Type Parameters

T

Exceptions

InvalidOperationException

Atn2<T>(T, T)

ATN2 (Transact-SQL)

Returns the angle, in radians, between the positive x-axis and the ray from the origin to the point (y, x), where x and y are the values of the two specified float expressions.

[Sql.Function("SqlServer", "ATN2", ServerSideOnly = true, IgnoreGenericParameters = true)]
public static T Atn2<T>(T float_expression, T float_expression2)

Parameters

float_expression T

An expression of type float.

float_expression2 T

Returns

T

float

Type Parameters

T

Exceptions

InvalidOperationException

BinaryCheckSum()

BINARY_CHECKSUM (Transact-SQL)

Returns the binary checksum value computed over a row of a table or over a list of expressions.

[Sql.Expression("SqlServer", "BINARY_CHECKSUM(*)", ServerSideOnly = true)]
public static int BinaryCheckSum()

Returns

int

int

Exceptions

InvalidOperationException

BinaryCheckSum(params object[])

BINARY_CHECKSUM (Transact-SQL)

Returns the binary checksum value computed over a row of a table or over a list of expressions.

[Sql.Function("SqlServer", "BINARY_CHECKSUM", ServerSideOnly = true)]
public static int BinaryCheckSum(params object[] expressions)

Parameters

expressions object[]

An expression of any type. BINARY_CHECKSUM ignores expressions of noncomparable data types in its computation.

Returns

int

int

Exceptions

InvalidOperationException

Cast<T>(object?)

CAST and CONVERT (Transact-SQL)

These functions convert an expression of one data type to another.

[Sql.Expression("SqlServer", "CAST({0} as {1})", ServerSideOnly = true)]
public static T Cast<T>(object? expression)

Parameters

expression object

Any valid expression.

Returns

T

Returns expression, translated to data_type.

Type Parameters

T

Exceptions

InvalidOperationException

Cast<T>(object?, SqlType<T>)

CAST and CONVERT (Transact-SQL)

These functions convert an expression of one data type to another.

[Sql.Extension("SqlServer", "CAST({expression} as {data_type})", ServerSideOnly = true, BuilderType = typeof(SqlFn.DataTypeBuilder))]
public static T Cast<T>(object? expression, SqlType<T> data_type)

Parameters

expression object

Any valid expression.

data_type SqlType<T>

The target data type. This includes xml, bigint, and sql_variant. Alias data types cannot be used.

Returns

T

Returns expression, translated to data_type.

Type Parameters

T

Exceptions

InvalidOperationException

Cast<T>(object?, Func<SqlType<T>>)

CAST and CONVERT (Transact-SQL)

These functions convert an expression of one data type to another.

[Sql.Extension("SqlServer", "CAST({expression} as {data_type})", ServerSideOnly = true, BuilderType = typeof(SqlFn.DataTypeBuilder))]
public static T Cast<T>(object? expression, Func<SqlType<T>> data_type)

Parameters

expression object

Any valid expression.

data_type Func<SqlType<T>>

The target data type. This includes xml, bigint, and sql_variant. Alias data types cannot be used.

Returns

T

Returns expression, translated to data_type.

Type Parameters

T

Exceptions

InvalidOperationException

Ceiling<T>(T)

CEILING (Transact-SQL)

This function returns the smallest integer greater than, or equal to, the specified numeric expression.

[Sql.Function("SqlServer", "CEILING", ServerSideOnly = true, IgnoreGenericParameters = true)]
public static T Ceiling<T>(T numeric_expression)

Parameters

numeric_expression T

An expression of the exact numeric or approximate numeric data type category. For this function, the bit data type is invalid.

Returns

T

Return values have the same type as numeric_expression.

Type Parameters

T

Exceptions

InvalidOperationException

Char(int?)

CHAR (Transact-SQL)

Returns the ASCII code value of the leftmost character of a character expression.

[Sql.Function("SqlServer", "CHAR", ServerSideOnly = true)]
public static char? Char(int? integer_expression)

Parameters

integer_expression int?

An integer from 0 through 255. CHAR returns a NULL value for integer expressions outside this input range or not representing a complete character. CHAR also returns a NULL value when the character exceeds the length of the return type. Many common character sets share ASCII as a sub-set and will return the same character for integer values in the range 0 through 127.

Returns

char?

char(1)

Exceptions

InvalidOperationException

CharIndex(string?, string?)

CHARINDEX (Transact-SQL)

This function searches for one character expression inside a second character expression, returning the starting position of the first expression if found.

[Sql.Function("SqlServer", "CHARINDEX", ServerSideOnly = true)]
public static int? CharIndex(string? expressionToFind, string? expressionToSearch)

Parameters

expressionToFind string

A character expression containing the sequence to find. expressionToFind has an 8000 character limit.

expressionToSearch string

A character expression to search.

Returns

int?

bigint if expressionToSearch has an nvarchar(max), varbinary(max), or varchar(max) data type; int otherwise.

Exceptions

InvalidOperationException

CharIndex(string?, string?, int?)

CHARINDEX (Transact-SQL)

This function searches for one character expression inside a second character expression, returning the starting position of the first expression if found.

[Sql.Function("SqlServer", "CHARINDEX", ServerSideOnly = true)]
public static int? CharIndex(string? expressionToFind, string? expressionToSearch, int? start_location)

Parameters

expressionToFind string

A character expression containing the sequence to find. expressionToFind has an 8000 character limit.

expressionToSearch string

A character expression to search.

start_location int?

An integer or bigint expression at which the search starts. If start_location is not specified, has a negative value, or has a zero (0) value, the search starts at the beginning of expressionToSearch.

Returns

int?

bigint if expressionToSearch has an nvarchar(max), varbinary(max), or varchar(max) data type; int otherwise.

Exceptions

InvalidOperationException

CharIndex(string?, string?, long?)

CHARINDEX (Transact-SQL)

This function searches for one character expression inside a second character expression, returning the starting position of the first expression if found.

[Sql.Function("SqlServer", "CHARINDEX", ServerSideOnly = true)]
public static long? CharIndex(string? expressionToFind, string? expressionToSearch, long? start_location)

Parameters

expressionToFind string

A character expression containing the sequence to find. expressionToFind has an 8000 character limit.

expressionToSearch string

A character expression to search.

start_location long?

An integer or bigint expression at which the search starts. If start_location is not specified, has a negative value, or has a zero (0) value, the search starts at the beginning of expressionToSearch.

Returns

long?

bigint if expressionToSearch has an nvarchar(max), varbinary(max), or varchar(max) data type; int otherwise.

Exceptions

InvalidOperationException

CharIndexBig(string?, string?)

CHARINDEX (Transact-SQL)

This function searches for one character expression inside a second character expression, returning the starting position of the first expression if found.

[Sql.Function("SqlServer", "CHARINDEX", ServerSideOnly = true)]
public static long? CharIndexBig(string? expressionToFind, string? expressionToSearch)

Parameters

expressionToFind string

A character expression containing the sequence to find. expressionToFind has an 8000 character limit.

expressionToSearch string

A character expression to search.

Returns

long?

bigint if expressionToSearch has an nvarchar(max), varbinary(max), or varchar(max) data type; int otherwise.

Exceptions

InvalidOperationException

CharIndexBig(string?, string?, int?)

CHARINDEX (Transact-SQL)

This function searches for one character expression inside a second character expression, returning the starting position of the first expression if found.

[Sql.Function("SqlServer", "CHARINDEX", ServerSideOnly = true)]
public static long? CharIndexBig(string? expressionToFind, string? expressionToSearch, int? start_location)

Parameters

expressionToFind string

A character expression containing the sequence to find. expressionToFind has an 8000 character limit.

expressionToSearch string

A character expression to search.

start_location int?

An integer or bigint expression at which the search starts. If start_location is not specified, has a negative value, or has a zero (0) value, the search starts at the beginning of expressionToSearch.

Returns

long?

bigint if expressionToSearch has an nvarchar(max), varbinary(max), or varchar(max) data type; int otherwise.

Exceptions

InvalidOperationException

CheckSum()

CHECKSUM (Transact-SQL)

The CHECKSUM function returns the checksum value computed over a table row, or over an expression list. Use CHECKSUM to build hash indexes.

[Sql.Expression("SqlServer", "CHECKSUM(*)", ServerSideOnly = true)]
public static int CheckSum()

Returns

int

int

Exceptions

InvalidOperationException

CheckSum(params object[])

CHECKSUM (Transact-SQL)

The CHECKSUM function returns the checksum value computed over a table row, or over an expression list. Use CHECKSUM to build hash indexes.

[Sql.Function("SqlServer", "CHECKSUM", ServerSideOnly = true)]
public static int CheckSum(params object[] expressions)

Parameters

expressions object[]

An expression of any type, except a noncomparable data type.

Returns

int

int

Exceptions

InvalidOperationException

Choose<T>(int?, params T[])

CHOOSE (Transact-SQL)

Returns the last identity value generated for a specified table or view. The last identity value generated can be for any session and any scope.

[Sql.Function("SqlServer", "CHOOSE", ServerSideOnly = true, IgnoreGenericParameters = true)]
public static T Choose<T>(int? index, params T[] values)

Parameters

index int?

Is an integer expression that represents a 1-based index into the list of the items following it.

values T[]

List of comma separated values of any data type.

Returns

T

Returns the data type with the highest precedence from the set of types passed to the function.

Type Parameters

T

Exceptions

InvalidOperationException

Collate(string?, string)

COLLATE (Transact-SQL)

Returns a character expression after converting uppercase character data to lowercase.

Windows_collation_name is the collation name for a Windows Collation Name.

Collation and Unicode support
[Sql.Extension("SqlServer", "{string} COLLATE {collation_name}", ServerSideOnly = true, BuilderType = typeof(SqlFn.CollateBuilder))]
public static string? Collate(string? @string, string collation_name)

Parameters

string string
collation_name string

Is the name of the collation to be applied to the expression, column definition, or database definition. collation_name can be only a specified Windows_collation_name or a SQL_collation_name. collation_name must be a literal value. collation_name cannot be represented by a variable or expression.

Returns

string

Exceptions

InvalidOperationException

ColumnLength(string, string)

COL_LENGTH (Transact-SQL)

This function returns the defined length of a column, in bytes.

[Sql.Function("SqlServer", "COL_LENGTH", ServerSideOnly = true)]
public static short? ColumnLength(string table, string column)

Parameters

table string

The name of the table whose column length information we want to determine. table is an expression of type nvarchar.

column string

The column name whose length we want to determine. column is an expression of type nvarchar.

Returns

short?

smallint

Exceptions

InvalidOperationException

ColumnName(int?, int)

COL_NAME (Transact-SQL)

This function returns the name of a table column, based on the table identification number and column identification number values of that table column.

[Sql.Function("SqlServer", "COL_NAME", ServerSideOnly = true)]
public static string? ColumnName(int? table_id, int column_id)

Parameters

table_id int?

The identification number of the table containing that column. The table_id argument has an int data type.

column_id int

The identification number of the column. The column_id argument has an int data type.

Returns

string

sysname

Exceptions

InvalidOperationException

ColumnProperty(int?, string, ColumnPropertyName)

COLUMNPROPERTY (Transact-SQL)

This function returns column or parameter information.

[Sql.Extension("SqlServer", "COLUMNPROPERTY", ServerSideOnly = true, BuilderType = typeof(SqlFn.PropertyBuilder<SqlFn.ColumnPropertyName>))]
public static int? ColumnProperty(int? id, string column, SqlFn.ColumnPropertyName property)

Parameters

id int?

An expression containing the identifier (ID) of the table or procedure.

column string

An expression containing the name of the column or parameter.

property SqlFn.ColumnPropertyName

For the id argument, the property argument specifies the information type that the COLUMNPROPERTY function will return.

Returns

int?

int

Exceptions

InvalidOperationException

Compress(byte[]?)

COMPRESS (Transact-SQL)

This function compresses the input expression, using the GZIP algorithm. The function returns a byte array of type varbinary(max).

[Sql.Function("SqlServer", "COMPRESS", ServerSideOnly = true)]
public static byte[] Compress(byte[]? expression)

Parameters

expression byte[]

A

  • binary(n)
  • char(n)
  • nchar(n)
  • nvarchar(max)
  • nvarchar(n)
  • varbinary(max)
  • varbinary(n)
  • varchar(max)
or
  • varchar(n)
expression.

Returns

byte[]

varbinary(max) representing the compressed content of the input.

Exceptions

InvalidOperationException

Compress(string?)

COMPRESS (Transact-SQL)

This function compresses the input expression, using the GZIP algorithm. The function returns a byte array of type varbinary(max).

[Sql.Function("SqlServer", "COMPRESS", ServerSideOnly = true)]
public static byte[] Compress(string? expression)

Parameters

expression string

A

  • binary(n)
  • char(n)
  • nchar(n)
  • nvarchar(max)
  • nvarchar(n)
  • varbinary(max)
  • varbinary(n)
  • varchar(max)
or
  • varchar(n)
expression.

Returns

byte[]

varbinary(max) representing the compressed content of the input.

Exceptions

InvalidOperationException

Concat(params string?[])

CONCAT (Transact-SQL)

This function returns a string resulting from the concatenation, or joining, of two or more string values in an end-to-end manner.

[Sql.Function("SqlServer", "CONCAT", ServerSideOnly = true)]
public static string? Concat(params string?[] string_value)

Parameters

string_value string[]

A string value to concatenate to the other values. The CONCAT function requires at least two string_value arguments, and no more than 254 string_value arguments.

Returns

string

string_value

Exceptions

InvalidOperationException

ConcatWithSeparator(string?, params string?[])

CONCAT_WS (Transact-SQL)

This function returns a string resulting from the concatenation, or joining, of two or more string values in an end-to-end manner. It separates those concatenated string values with the delimiter specified in the first function argument. (CONCAT_WS indicates concatenate with separator.)

[Sql.Function("SqlServer", "CONCAT_WS", ServerSideOnly = true)]
public static string? ConcatWithSeparator(string? separator, params string?[] arguments)

Parameters

separator string

An expression of any character type (char, nchar, nvarchar, or varchar).

arguments string[]

An expression of any type. The CONCAT_WS function requires at least two arguments, and no more than 254 arguments.

Returns

string

A string value whose length and type depend on the input.

Exceptions

InvalidOperationException

ConnectionProperty(ConnectionPropertyName)

CONNECTIONPROPERTY (Transact-SQL)

For a request that comes in to the server, this function returns information about the connection properties of the unique connection which supports that request.

[Sql.Extension("SqlServer", "CONNECTIONPROPERTY", ServerSideOnly = true, BuilderType = typeof(SqlFn.PropertyBuilder<SqlFn.ConnectionPropertyName>))]
public static object? ConnectionProperty(SqlFn.ConnectionPropertyName property)

Parameters

property SqlFn.ConnectionPropertyName

The property of the connection.

Returns

object

int

Exceptions

InvalidOperationException

Convert<T>(SqlType<T>, object?)

CAST and CONVERT (Transact-SQL)

These functions convert an expression of one data type to another.

[Sql.Extension("SqlServer", "CONVERT({data_type}, {expression})", ServerSideOnly = true, BuilderType = typeof(SqlFn.DataTypeBuilder))]
public static T Convert<T>(SqlType<T> data_type, object? expression)

Parameters

data_type SqlType<T>

The target data type. This includes xml, bigint, and sql_variant. Alias data types cannot be used.

expression object

Any valid expression.

Returns

T

Returns expression, translated to data_type.

Type Parameters

T

Exceptions

InvalidOperationException

Convert<T>(SqlType<T>, object?, int)

CAST and CONVERT (Transact-SQL)

These functions convert an expression of one data type to another.

[Sql.Extension("SqlServer", "CONVERT({data_type}, {expression}, {style})", ServerSideOnly = true, BuilderType = typeof(SqlFn.DataTypeBuilder))]
public static T Convert<T>(SqlType<T> data_type, object? expression, int style)

Parameters

data_type SqlType<T>

The target data type. This includes xml, bigint, and sql_variant. Alias data types cannot be used.

expression object

Any valid expression.

style int

Returns

T

Returns expression, translated to data_type.

Type Parameters

T

Exceptions

InvalidOperationException

Convert<T>(Func<SqlType<T>>, object?)

CAST and CONVERT (Transact-SQL)

These functions convert an expression of one data type to another.

[Sql.Extension("SqlServer", "CONVERT({data_type}, {expression})", ServerSideOnly = true, BuilderType = typeof(SqlFn.DataTypeBuilder))]
public static T Convert<T>(Func<SqlType<T>> data_type, object? expression)

Parameters

data_type Func<SqlType<T>>

The target data type. This includes xml, bigint, and sql_variant. Alias data types cannot be used.

expression object

Any valid expression.

Returns

T

Returns expression, translated to data_type.

Type Parameters

T

Exceptions

InvalidOperationException

Convert<T>(Func<SqlType<T>>, object?, int)

CAST and CONVERT (Transact-SQL)

These functions convert an expression of one data type to another.

[Sql.Extension("SqlServer", "CONVERT({data_type}, {expression}, {style})", ServerSideOnly = true, BuilderType = typeof(SqlFn.DataTypeBuilder))]
public static T Convert<T>(Func<SqlType<T>> data_type, object? expression, int style)

Parameters

data_type Func<SqlType<T>>

The target data type. This includes xml, bigint, and sql_variant. Alias data types cannot be used.

expression object

Any valid expression.

style int

Returns

T

Returns expression, translated to data_type.

Type Parameters

T

Exceptions

InvalidOperationException

Convert<T>(object?)

CAST and CONVERT (Transact-SQL)

These functions convert an expression of one data type to another.

[Sql.Expression("SqlServer", "CONVERT({1}, {0})", ServerSideOnly = true)]
public static T Convert<T>(object? expression)

Parameters

expression object

Any valid expression.

Returns

T

Returns expression, translated to data_type.

Type Parameters

T

Exceptions

InvalidOperationException

Convert<T>(object?, int)

CAST and CONVERT (Transact-SQL)

These functions convert an expression of one data type to another.

[Sql.Expression("SqlServer", "CONVERT({2}, {0}, {1})", ServerSideOnly = true)]
public static T Convert<T>(object? expression, int style)

Parameters

expression object

Any valid expression.

style int

Returns

T

Returns expression, translated to data_type.

Type Parameters

T

Exceptions

InvalidOperationException

Cos<T>(T)

COS (Transact-SQL)

A mathematical function that returns the trigonometric cosine of the specified angle - measured in radians - in the specified expression.

[Sql.Function("SqlServer", "COS", ServerSideOnly = true, IgnoreGenericParameters = true)]
public static T Cos<T>(T float_expression)

Parameters

float_expression T

An expression of type float.

Returns

T

float

Type Parameters

T

Exceptions

InvalidOperationException

Cot<T>(T)

COT (Transact-SQL)

A mathematical function that returns the trigonometric cotangent of the specified angle - in radians - in the specified float expression.

[Sql.Function("SqlServer", "COT", ServerSideOnly = true, IgnoreGenericParameters = true)]
public static T Cot<T>(T float_expression)

Parameters

float_expression T

An expression of type float, or of a type that can implicitly convert to float.

Returns

T

float

Type Parameters

T

Exceptions

InvalidOperationException

CurrentRequestID()

CURRENT_REQUEST_ID (Transact-SQL)

This function returns the ID of the current request within the current session.

[Sql.Function("SqlServer", "CURRENT_REQUEST_ID", ServerSideOnly = true)]
public static short CurrentRequestID()

Returns

short

smallint

Exceptions

InvalidOperationException

CurrentTimezone()

CURRENT_TIMEZONE (Transact-SQL)

This function returns the name of the time zone observed by a server or an instance. For SQL Managed Instance, return value is based on the time zone of the instance itself assigned during instance creation, not the time zone of the underlying operating system.

[Sql.Function("SqlServer", "CURRENT_TIMEZONE", ServerSideOnly = true, IgnoreGenericParameters = true)]
public static string CurrentTimezone()

Returns

string

varchar

Exceptions

InvalidOperationException

CurrentTimezoneID()

CURRENT_TIMEZONE_ID (Transact-SQL)

This function returns the ID of the time zone observed by a server or an instance. For Azure SQL Managed Instance, return value is based on the time zone of the instance itself assigned during instance creation, not the time zone of the underlying operating system.

[Sql.Function("SqlServer", "CURRENT_TIMEZONE_ID", ServerSideOnly = true, IgnoreGenericParameters = true)]
public static string CurrentTimezoneID()

Returns

string

varchar

Exceptions

InvalidOperationException

CurrentTransactionID()

CURRENT_TRANSACTION_ID (Transact-SQL)

This function returns the transaction ID of the current transaction in the current session.

[Sql.Function("SqlServer", "CURRENT_TRANSACTION_ID", ServerSideOnly = true)]
public static long CurrentTransactionID()

Returns

long

bigint

Exceptions

InvalidOperationException

DataLengthBig<T>(T)

DATALENGTH (Transact-SQL)

This function returns the number of bytes used to represent any expression.

DATALENGTH becomes really helpful when used with data types that can store variable-length data, such as:
  • ntext
  • nvarchar
  • text
  • varbinary
  • varchar

For a NULL value, DATALENGTH returns NULL.

Use the LEN to return the number of characters encoded into a given string expression, and DATALENGTH to return the size in bytes for a given string expression. These outputs may differ depending on the data type and type of encoding used in the column. For more information on storage differences between different encoding types, see Collation and Unicode Support.
[Sql.Function("SqlServer", "DATALENGTH", new int[] { 0 }, ServerSideOnly = true)]
[CLSCompliant(false)]
public static long? DataLengthBig<T>(T expression)

Parameters

expression T

An expression of any data type.

Returns

long?

bigint if expression has an nvarchar(max), varbinary(max), or varchar(max) data type; otherwise int.

Type Parameters

T

An expression of any data type.

Exceptions

InvalidOperationException

DataLength<T>(T)

DATALENGTH (Transact-SQL)

This function returns the number of bytes used to represent any expression.

DATALENGTH becomes really helpful when used with data types that can store variable-length data, such as:
  • ntext
  • nvarchar
  • text
  • varbinary
  • varchar

For a NULL value, DATALENGTH returns NULL.

Use the LEN to return the number of characters encoded into a given string expression, and DATALENGTH to return the size in bytes for a given string expression. These outputs may differ depending on the data type and type of encoding used in the column. For more information on storage differences between different encoding types, see Collation and Unicode Support.
[Sql.Function("SqlServer", "DATALENGTH", new int[] { 0 }, ServerSideOnly = true)]
[CLSCompliant(false)]
public static int? DataLength<T>(T expression)

Parameters

expression T

An expression of any data type.

Returns

int?

bigint if expression has an nvarchar(max), varbinary(max), or varchar(max) data type; otherwise int.

Type Parameters

T

An expression of any data type.

Exceptions

InvalidOperationException

DatabasePropertyEx(string, DatabasePropertyName)

DATABASEPROPERTYEX (Transact-SQL)

For a specified database in SQL Server, this function returns the current setting of the specified database option or property.

[Sql.Extension("SqlServer", "DATABASEPROPERTYEX", ServerSideOnly = true, BuilderType = typeof(SqlFn.PropertyBuilder<SqlFn.DatabasePropertyName>))]
public static object? DatabasePropertyEx(string database, SqlFn.DatabasePropertyName property)

Parameters

database string

An expression specifying the name of the database for which DATABASEPROPERTYEX will return the named property information. database has an nvarchar(128) data type.

property SqlFn.DatabasePropertyName

An expression specifying the name of the database property to return. property has a varchar(128) data type

Returns

object

sql_variant

Exceptions

InvalidOperationException

DateAdd(DateParts, int?, DateTimeOffset?)

DATEADD (Transact-SQL)

This function adds a number (a signed integer) to a datepart of an input date, and returns a modified date/time value.

[Sql.Extension("SqlServer", "DATEADD({datepart}, {number}, {date})", ServerSideOnly = true, BuilderType = typeof(SqlFn.DatePartBuilder))]
public static DateTimeOffset? DateAdd(SqlFn.DateParts datepart, int? number, DateTimeOffset? date)

Parameters

datepart SqlFn.DateParts

The part of date to which DATEADD adds an integer number. This table lists all valid datepart arguments.

number int?

An expression that can resolve to an int that DATEADD adds to a datepart of date. DATEADD accepts user-defined variable values for number. DATEADD will truncate a specified number value that has a decimal fraction. It will not round the number value in this situation.

date DateTimeOffset?

Returns

DateTimeOffset?

varchar

Exceptions

InvalidOperationException

DateAdd(DateParts, int?, DateTime?)

DATEADD (Transact-SQL)

This function adds a number (a signed integer) to a datepart of an input date, and returns a modified date/time value.

[Sql.Extension("SqlServer", "DATEADD({datepart}, {number}, {date})", ServerSideOnly = true, BuilderType = typeof(SqlFn.DatePartBuilder))]
public static DateTime? DateAdd(SqlFn.DateParts datepart, int? number, DateTime? date)

Parameters

datepart SqlFn.DateParts

The part of date to which DATEADD adds an integer number. This table lists all valid datepart arguments.

number int?

An expression that can resolve to an int that DATEADD adds to a datepart of date. DATEADD accepts user-defined variable values for number. DATEADD will truncate a specified number value that has a decimal fraction. It will not round the number value in this situation.

date DateTime?

Returns

DateTime?

varchar

Exceptions

InvalidOperationException

DateAdd(DateParts, int?, TimeSpan?)

DATEADD (Transact-SQL)

This function adds a number (a signed integer) to a datepart of an input date, and returns a modified date/time value.

[Sql.Extension("SqlServer", "DATEADD({datepart}, {number}, {date})", ServerSideOnly = true, BuilderType = typeof(SqlFn.DatePartBuilder))]
public static TimeSpan? DateAdd(SqlFn.DateParts datepart, int? number, TimeSpan? date)

Parameters

datepart SqlFn.DateParts

The part of date to which DATEADD adds an integer number. This table lists all valid datepart arguments.

number int?

An expression that can resolve to an int that DATEADD adds to a datepart of date. DATEADD accepts user-defined variable values for number. DATEADD will truncate a specified number value that has a decimal fraction. It will not round the number value in this situation.

date TimeSpan?

Returns

TimeSpan?

varchar

Exceptions

InvalidOperationException

DateAdd(DateParts, int?, string?)

DATEADD (Transact-SQL)

This function adds a number (a signed integer) to a datepart of an input date, and returns a modified date/time value.

[Sql.Extension("SqlServer", "DATEADD({datepart}, {number}, {date})", ServerSideOnly = true, BuilderType = typeof(SqlFn.DatePartBuilder))]
public static DateTime? DateAdd(SqlFn.DateParts datepart, int? number, string? date)

Parameters

datepart SqlFn.DateParts

The part of date to which DATEADD adds an integer number. This table lists all valid datepart arguments.

number int?

An expression that can resolve to an int that DATEADD adds to a datepart of date. DATEADD accepts user-defined variable values for number. DATEADD will truncate a specified number value that has a decimal fraction. It will not round the number value in this situation.

date string

Returns

DateTime?

varchar

Exceptions

InvalidOperationException

DateDiff(DateParts, DateTimeOffset?, DateTimeOffset?)

DATEDIFF (Transact-SQL)

This function returns the count (as a signed integer value) of the specified datepart boundaries crossed between the specified startdate and enddate.

[Sql.Extension("SqlServer", "DATEDIFF({datepart}, {startdate}, {enddate})", ServerSideOnly = true, BuilderType = typeof(SqlFn.DatePartBuilder))]
public static int? DateDiff(SqlFn.DateParts datepart, DateTimeOffset? startdate, DateTimeOffset? enddate)

Parameters

datepart SqlFn.DateParts
startdate DateTimeOffset?
enddate DateTimeOffset?

Returns

int?

int

Exceptions

InvalidOperationException

DateDiff(DateParts, DateTime?, DateTime?)

DATEDIFF (Transact-SQL)

This function returns the count (as a signed integer value) of the specified datepart boundaries crossed between the specified startdate and enddate.

[Sql.Extension("SqlServer", "DATEDIFF({datepart}, {startdate}, {enddate})", ServerSideOnly = true, BuilderType = typeof(SqlFn.DatePartBuilder))]
public static int? DateDiff(SqlFn.DateParts datepart, DateTime? startdate, DateTime? enddate)

Parameters

datepart SqlFn.DateParts
startdate DateTime?
enddate DateTime?

Returns

int?

int

Exceptions

InvalidOperationException

DateDiff(DateParts, TimeSpan?, TimeSpan?)

DATEDIFF (Transact-SQL)

This function returns the count (as a signed integer value) of the specified datepart boundaries crossed between the specified startdate and enddate.

[Sql.Extension("SqlServer", "DATEDIFF({datepart}, {startdate}, {enddate})", ServerSideOnly = true, BuilderType = typeof(SqlFn.DatePartBuilder))]
public static int? DateDiff(SqlFn.DateParts datepart, TimeSpan? startdate, TimeSpan? enddate)

Parameters

datepart SqlFn.DateParts
startdate TimeSpan?
enddate TimeSpan?

Returns

int?

int

Exceptions

InvalidOperationException

DateDiff(DateParts, string?, string?)

DATEDIFF (Transact-SQL)

This function returns the count (as a signed integer value) of the specified datepart boundaries crossed between the specified startdate and enddate.

[Sql.Extension("SqlServer", "DATEDIFF({datepart}, {startdate}, {enddate})", ServerSideOnly = true, BuilderType = typeof(SqlFn.DatePartBuilder))]
public static int? DateDiff(SqlFn.DateParts datepart, string? startdate, string? enddate)

Parameters

datepart SqlFn.DateParts
startdate string
enddate string

Returns

int?

int

Exceptions

InvalidOperationException

DateDiffBig(DateParts, DateTimeOffset?, DateTimeOffset?)

DATEDIFF_BIG (Transact-SQL)

This function returns the count (as a signed integer value) of the specified datepart boundaries crossed between the specified startdate and enddate.

[Sql.Extension("SqlServer", "DATEDIFF_BIG({datepart}, {startdate}, {enddate})", ServerSideOnly = true, BuilderType = typeof(SqlFn.DatePartBuilder))]
public static long? DateDiffBig(SqlFn.DateParts datepart, DateTimeOffset? startdate, DateTimeOffset? enddate)

Parameters

datepart SqlFn.DateParts
startdate DateTimeOffset?
enddate DateTimeOffset?

Returns

long?

bigint

Exceptions

InvalidOperationException

DateDiffBig(DateParts, DateTime?, DateTime?)

DATEDIFF_BIG (Transact-SQL)

This function returns the count (as a signed integer value) of the specified datepart boundaries crossed between the specified startdate and enddate.

[Sql.Extension("SqlServer", "DATEDIFF_BIG({datepart}, {startdate}, {enddate})", ServerSideOnly = true, BuilderType = typeof(SqlFn.DatePartBuilder))]
public static long? DateDiffBig(SqlFn.DateParts datepart, DateTime? startdate, DateTime? enddate)

Parameters

datepart SqlFn.DateParts
startdate DateTime?
enddate DateTime?

Returns

long?

bigint

Exceptions

InvalidOperationException

DateDiffBig(DateParts, TimeSpan?, TimeSpan?)

DATEDIFF_BIG (Transact-SQL)

This function returns the count (as a signed integer value) of the specified datepart boundaries crossed between the specified startdate and enddate.

[Sql.Extension("SqlServer", "DATEDIFF_BIG({datepart}, {startdate}, {enddate})", ServerSideOnly = true, BuilderType = typeof(SqlFn.DatePartBuilder))]
public static long? DateDiffBig(SqlFn.DateParts datepart, TimeSpan? startdate, TimeSpan? enddate)

Parameters

datepart SqlFn.DateParts
startdate TimeSpan?
enddate TimeSpan?

Returns

long?

bigint

Exceptions

InvalidOperationException

DateDiffBig(DateParts, string?, string?)

DATEDIFF_BIG (Transact-SQL)

This function returns the count (as a signed integer value) of the specified datepart boundaries crossed between the specified startdate and enddate.

[Sql.Extension("SqlServer", "DATEDIFF_BIG({datepart}, {startdate}, {enddate})", ServerSideOnly = true, BuilderType = typeof(SqlFn.DatePartBuilder))]
public static long? DateDiffBig(SqlFn.DateParts datepart, string? startdate, string? enddate)

Parameters

datepart SqlFn.DateParts
startdate string
enddate string

Returns

long?

bigint

Exceptions

InvalidOperationException

DateFromParts(int?, int?, int?)

DATEFROMPARTS (Transact-SQL)

This function returns a date value that maps to the specified year, month, and day values.

[Sql.Function("SqlServer", "DATEFROMPARTS", ServerSideOnly = true)]
public static DateTime? DateFromParts(int? year, int? month, int? day)

Parameters

year int?

An integer expression that specifies a year.

month int?

An integer expression that specifies a month, from 1 to 12.

day int?

An integer expression that specifies a day.

Returns

DateTime?

date

Exceptions

InvalidOperationException

DateName(DateParts, DateTimeOffset?)

DATENAME (Transact-SQL)

This function returns a character string representing the specified datepart of the specified date.

[Sql.Extension("SqlServer", "DATENAME({datepart}, {date})", ServerSideOnly = true, BuilderType = typeof(SqlFn.DatePartBuilder))]
public static string? DateName(SqlFn.DateParts datepart, DateTimeOffset? date)

Parameters

datepart SqlFn.DateParts

The specific part of the date argument that DATENAME will return. This table lists all valid datepart arguments.

date DateTimeOffset?

Returns

string

nvarchar

Exceptions

InvalidOperationException

DateName(DateParts, DateTime?)

DATENAME (Transact-SQL)

This function returns a character string representing the specified datepart of the specified date.

[Sql.Extension("SqlServer", "DATENAME({datepart}, {date})", ServerSideOnly = true, BuilderType = typeof(SqlFn.DatePartBuilder))]
public static string? DateName(SqlFn.DateParts datepart, DateTime? date)

Parameters

datepart SqlFn.DateParts

The specific part of the date argument that DATENAME will return. This table lists all valid datepart arguments.

date DateTime?

Returns

string

nvarchar

Exceptions

InvalidOperationException

DateName(DateParts, TimeSpan?)

DATENAME (Transact-SQL)

This function returns a character string representing the specified datepart of the specified date.

[Sql.Extension("SqlServer", "DATENAME({datepart}, {date})", ServerSideOnly = true, BuilderType = typeof(SqlFn.DatePartBuilder))]
public static string? DateName(SqlFn.DateParts datepart, TimeSpan? date)

Parameters

datepart SqlFn.DateParts

The specific part of the date argument that DATENAME will return. This table lists all valid datepart arguments.

date TimeSpan?

Returns

string

nvarchar

Exceptions

InvalidOperationException

DateName(DateParts, string?)

DATENAME (Transact-SQL)

This function returns a character string representing the specified datepart of the specified date.

[Sql.Extension("SqlServer", "DATENAME({datepart}, {date})", ServerSideOnly = true, BuilderType = typeof(SqlFn.DatePartBuilder))]
public static string? DateName(SqlFn.DateParts datepart, string? date)

Parameters

datepart SqlFn.DateParts

The specific part of the date argument that DATENAME will return. This table lists all valid datepart arguments.

date string

Returns

string

nvarchar

Exceptions

InvalidOperationException

DatePart(DateParts, DateTimeOffset?)

DATEPART (Transact-SQL)

This function returns an integer representing the specified datepart of the specified date.

[Sql.Extension("SqlServer", "DATEPART({datepart}, {date})", ServerSideOnly = true, BuilderType = typeof(SqlFn.DatePartBuilder))]
public static int? DatePart(SqlFn.DateParts datepart, DateTimeOffset? date)

Parameters

datepart SqlFn.DateParts

The specific part of the date argument for which DATEPART will return an integer. This table lists all valid datepart arguments.

date DateTimeOffset?

Returns

int?

int

Exceptions

InvalidOperationException

DatePart(DateParts, DateTime?)

DATEPART (Transact-SQL)

This function returns an integer representing the specified datepart of the specified date.

[Sql.Extension("SqlServer", "DATEPART({datepart}, {date})", ServerSideOnly = true, BuilderType = typeof(SqlFn.DatePartBuilder))]
public static int? DatePart(SqlFn.DateParts datepart, DateTime? date)

Parameters

datepart SqlFn.DateParts

The specific part of the date argument for which DATEPART will return an integer. This table lists all valid datepart arguments.

date DateTime?

Returns

int?

int

Exceptions

InvalidOperationException

DatePart(DateParts, TimeSpan?)

DATEPART (Transact-SQL)

This function returns an integer representing the specified datepart of the specified date.

[Sql.Extension("SqlServer", "DATEPART({datepart}, {date})", ServerSideOnly = true, BuilderType = typeof(SqlFn.DatePartBuilder))]
public static int? DatePart(SqlFn.DateParts datepart, TimeSpan? date)

Parameters

datepart SqlFn.DateParts

The specific part of the date argument for which DATEPART will return an integer. This table lists all valid datepart arguments.

date TimeSpan?

Returns

int?

int

Exceptions

InvalidOperationException

DatePart(DateParts, string?)

DATEPART (Transact-SQL)

This function returns an integer representing the specified datepart of the specified date.

[Sql.Extension("SqlServer", "DATEPART({datepart}, {date})", ServerSideOnly = true, BuilderType = typeof(SqlFn.DatePartBuilder))]
public static int? DatePart(SqlFn.DateParts datepart, string? date)

Parameters

datepart SqlFn.DateParts

The specific part of the date argument for which DATEPART will return an integer. This table lists all valid datepart arguments.

date string

Returns

int?

int

Exceptions

InvalidOperationException

DateTime2FromParts(int?, int?, int?)

DATETIME2FROMPARTS (Transact-SQL)

This function returns a datetime2 value for the specified date and time arguments.

[Sql.Expression("SqlServer", "DATETIME2FROMPARTS({0}, {1}, {2}, 0, 0, 0, 0, 0)", ServerSideOnly = true)]
public static DateTime? DateTime2FromParts(int? year, int? month, int? day)

Parameters

year int?
month int?
day int?

Returns

DateTime?

datetime2

Exceptions

InvalidOperationException

DateTime2FromParts(int?, int?, int?, int?, int?, int?)

DATETIME2FROMPARTS (Transact-SQL)

This function returns a datetime2 value for the specified date and time arguments.

[Sql.Expression("SqlServer", "DATETIME2FROMPARTS({0}, {1}, {2}, {3}, {4}, {5}, 0, 0)", ServerSideOnly = true)]
public static DateTime? DateTime2FromParts(int? year, int? month, int? day, int? hour, int? minute, int? seconds)

Parameters

year int?
month int?
day int?
hour int?
minute int?
seconds int?

Returns

DateTime?

datetime2

Exceptions

InvalidOperationException

DateTime2FromParts(int?, int?, int?, int?, int?, int?, int?, int?)

DATETIME2FROMPARTS (Transact-SQL)

This function returns a datetime2 value for the specified date and time arguments.

[Sql.Function("SqlServer", "DATETIME2FROMPARTS", ServerSideOnly = true)]
public static DateTime? DateTime2FromParts(int? year, int? month, int? day, int? hour, int? minute, int? seconds, int? fractions, int? precision)

Parameters

year int?
month int?
day int?
hour int?
minute int?
seconds int?
fractions int?
precision int?

Returns

DateTime?

datetime2

Exceptions

InvalidOperationException

DateTimeFromParts(int?, int?, int?)

DATETIMEFROMPARTS (Transact-SQL)

This function returns a datetime value for the specified date and time arguments.

[Sql.Expression("SqlServer", "DATETIMEFROMPARTS({0}, {1}, {2}, 0, 0, 0, 0)", ServerSideOnly = true)]
public static DateTime? DateTimeFromParts(int? year, int? month, int? day)

Parameters

year int?
month int?
day int?

Returns

DateTime?

datetime

Exceptions

InvalidOperationException

DateTimeFromParts(int?, int?, int?, int?, int?, int?)

DATETIMEFROMPARTS (Transact-SQL)

This function returns a datetime value for the specified date and time arguments.

[Sql.Expression("SqlServer", "DATETIMEFROMPARTS({0}, {1}, {2}, {3}, {4}, {5}, 0)", ServerSideOnly = true)]
public static DateTime? DateTimeFromParts(int? year, int? month, int? day, int? hour, int? minute, int? seconds)

Parameters

year int?
month int?
day int?
hour int?
minute int?
seconds int?

Returns

DateTime?

datetime

Exceptions

InvalidOperationException

DateTimeFromParts(int?, int?, int?, int?, int?, int?, int?)

DATETIMEFROMPARTS (Transact-SQL)

This function returns a datetime value for the specified date and time arguments.

[Sql.Function("SqlServer", "DATETIMEFROMPARTS", ServerSideOnly = true)]
public static DateTime? DateTimeFromParts(int? year, int? month, int? day, int? hour, int? minute, int? seconds, int? milliseconds)

Parameters

year int?
month int?
day int?
hour int?
minute int?
seconds int?
milliseconds int?

Returns

DateTime?

datetime

Exceptions

InvalidOperationException

DateTimeOffsetFromParts(int?, int?, int?)

DATETIMEOFFSETFROMPARTS (Transact-SQL)

Returns a datetimeoffset value for the specified date and time arguments. The returned value has a precision specified by the precision argument, and an offset as specified by the offset arguments.

[Sql.Expression("SqlServer", "DATETIMEOFFSETFROMPARTS({0}, {1}, {2}, 0, 0, 0, 0, 0, 0, 0)", ServerSideOnly = true)]
public static DateTimeOffset? DateTimeOffsetFromParts(int? year, int? month, int? day)

Parameters

year int?
month int?
day int?

Returns

DateTimeOffset?

datetimeoffset

Exceptions

InvalidOperationException

DateTimeOffsetFromParts(int?, int?, int?, int?, int?, int?)

DATETIMEOFFSETFROMPARTS (Transact-SQL)

Returns a datetimeoffset value for the specified date and time arguments. The returned value has a precision specified by the precision argument, and an offset as specified by the offset arguments.

[Sql.Expression("SqlServer", "DATETIMEOFFSETFROMPARTS({0}, {1}, {2}, {3}, {4}, {5}, 0, 0, 0, 0)", ServerSideOnly = true)]
public static DateTimeOffset? DateTimeOffsetFromParts(int? year, int? month, int? day, int? hour, int? minute, int? seconds)

Parameters

year int?
month int?
day int?
hour int?
minute int?
seconds int?

Returns

DateTimeOffset?

datetimeoffset

Exceptions

InvalidOperationException

DateTimeOffsetFromParts(int?, int?, int?, int?, int?, int?, int?, int?, int?, int?)

DATETIMEOFFSETFROMPARTS (Transact-SQL)

Returns a datetimeoffset value for the specified date and time arguments. The returned value has a precision specified by the precision argument, and an offset as specified by the offset arguments.

[Sql.Function("SqlServer", "DATETIMEOFFSETFROMPARTS", ServerSideOnly = true)]
public static DateTimeOffset? DateTimeOffsetFromParts(int? year, int? month, int? day, int? hour, int? minute, int? seconds, int? fractions, int? hour_offset, int? minute_offset, int? precision)

Parameters

year int?
month int?
day int?
hour int?
minute int?
seconds int?
fractions int?
hour_offset int?
minute_offset int?
precision int?

Returns

DateTimeOffset?

datetimeoffset

Exceptions

InvalidOperationException

Day(DateTimeOffset?)

DAY (Transact-SQL)

This function returns an integer that represents the day (day of the month) of the specified date.

[Sql.Function("SqlServer", "DAY", ServerSideOnly = true)]
public static int? Day(DateTimeOffset? date)

Parameters

date DateTimeOffset?

Returns

int?

int

Exceptions

InvalidOperationException

Day(DateTime?)

DAY (Transact-SQL)

This function returns an integer that represents the day (day of the month) of the specified date.

[Sql.Function("SqlServer", "DAY", ServerSideOnly = true)]
public static int? Day(DateTime? date)

Parameters

date DateTime?

Returns

int?

int

Exceptions

InvalidOperationException

Day(string?)

DAY (Transact-SQL)

This function returns an integer that represents the day (day of the month) of the specified date.

[Sql.Function("SqlServer", "DAY", ServerSideOnly = true)]
public static int? Day(string? date)

Parameters

date string

Returns

int?

int

Exceptions

InvalidOperationException

DbID()

DB_ID (Transact-SQL)

This function returns the database identification (ID) number of a specified database.

[Sql.Function("SqlServer", "DB_ID", ServerSideOnly = true)]
public static int DbID()

Returns

int

int

Exceptions

InvalidOperationException

DbID(string)

DB_ID (Transact-SQL)

This function returns the database identification (ID) number of a specified database.

[Sql.Function("SqlServer", "DB_ID", ServerSideOnly = true)]
public static int? DbID(string database_name)

Parameters

database_name string

The name of the database whose database ID number DB_ID will return. If the call to DB_ID omits database_name, DB_ID returns the ID of the current database.

Returns

int?

int

Exceptions

InvalidOperationException

DbName()

DB_NAME (Transact-SQL)

This function returns the name of a specified database.

[Sql.Function("SqlServer", "DB_NAME", ServerSideOnly = true)]
public static string DbName()

Returns

string

nvarchar(128)

Exceptions

InvalidOperationException

DbName(int)

DB_NAME (Transact-SQL)

This function returns the name of a specified database.

[Sql.Function("SqlServer", "DB_NAME", ServerSideOnly = true)]
public static string? DbName(int database_id)

Parameters

database_id int

The identification number (ID) of the database whose name DB_NAME will return. If the call to DB_NAME omits database_id, DB_NAME returns the name of the current database.

Returns

string

nvarchar(128)

Exceptions

InvalidOperationException

Decompress(byte[])

DECOMPRESS (Transact-SQL)

This function will decompress an input expression value, using the GZIP algorithm. DECOMPRESS will return a byte array (VARBINARY(MAX) type).

[Sql.Function("SqlServer", "DECOMPRESS", ServerSideOnly = true)]
public static byte[] Decompress(byte[] expression)

Parameters

expression byte[]

A varbinary(n), varbinary(max), or binary(n) value.

Returns

byte[]

varbinary(max) representing the compressed content of the input.

Exceptions

InvalidOperationException

Degrees<T>(T)

DEGREES (Transact-SQL)

This function returns the corresponding angle, in degrees, for an angle specified in radians.

[Sql.Function("SqlServer", "DEGREES", ServerSideOnly = true, IgnoreGenericParameters = true)]
public static T Degrees<T>(T numeric_expression)

Parameters

numeric_expression T

An expression of the exact numeric or approximate numeric data type category, except for the bit data type.

Returns

T

Return values have the same type as numeric_expression.

Type Parameters

T

Exceptions

InvalidOperationException

Difference(string?, string?)

DIFFERENCE (Transact-SQL)

This function returns an integer value measuring the difference between the SOUNDEX() values of two different character expressions.

[Sql.Function("SqlServer", "DIFFERENCE", ServerSideOnly = true)]
public static int? Difference(string? character_expression1, string? character_expression2)

Parameters

character_expression1 string

An alphanumeric expression of character data. character_expression can be a constant, variable, or column.

character_expression2 string

Returns

int?

int

Exceptions

InvalidOperationException

EndOfMonth(DateTime?)

EOMONTH (Transact-SQL)

This function returns the last day of the month containing a specified date, with an optional offset.

[Sql.Function("SqlServer", "EOMONTH", ServerSideOnly = true)]
public static DateTime? EndOfMonth(DateTime? start_date)

Parameters

start_date DateTime?

A date expression that specifies the date for which to return the last day of the month.

Returns

DateTime?

date

Exceptions

InvalidOperationException

EndOfMonth(DateTime?, int?)

EOMONTH (Transact-SQL)

This function returns the last day of the month containing a specified date, with an optional offset.

[Sql.Function("SqlServer", "EOMONTH", ServerSideOnly = true)]
public static DateTime? EndOfMonth(DateTime? start_date, int? month_to_add)

Parameters

start_date DateTime?

A date expression that specifies the date for which to return the last day of the month.

month_to_add int?

An optional integer expression that specifies the number of months to add to start_date.

Returns

DateTime?

date

Exceptions

InvalidOperationException

EndOfMonth(string?)

EOMONTH (Transact-SQL)

This function returns the last day of the month containing a specified date, with an optional offset.

[Sql.Function("SqlServer", "EOMONTH", ServerSideOnly = true)]
public static DateTime? EndOfMonth(string? start_date)

Parameters

start_date string

A date expression that specifies the date for which to return the last day of the month.

Returns

DateTime?

date

Exceptions

InvalidOperationException

EndOfMonth(string?, int?)

EOMONTH (Transact-SQL)

This function returns the last day of the month containing a specified date, with an optional offset.

[Sql.Function("SqlServer", "EOMONTH", ServerSideOnly = true)]
public static DateTime? EndOfMonth(string? start_date, int? month_to_add)

Parameters

start_date string

A date expression that specifies the date for which to return the last day of the month.

month_to_add int?

An optional integer expression that specifies the number of months to add to start_date.

Returns

DateTime?

date

Exceptions

InvalidOperationException

Exp<T>(T)

EXP (Transact-SQL)

Returns the exponential value of the specified float expression.

[Sql.Function("SqlServer", "EXP", ServerSideOnly = true, IgnoreGenericParameters = true)]
public static T Exp<T>(T float_expression)

Parameters

float_expression T

Is an expression of type float or of a type that can be implicitly converted to float.

Returns

T

float

Type Parameters

T

Exceptions

InvalidOperationException

FileGroupID(string?)

FILEGROUP_ID (Transact-SQL)

This function returns the filegroup identification (ID) number for a specified filegroup name.

[Sql.Function("SqlServer", "FILEGROUP_ID", ServerSideOnly = true)]
public static int? FileGroupID(string? filegroup_name)

Parameters

filegroup_name string

An expression of type sysname, representing the filegroup name whose filegroup ID FILEGROUP_ID will return.

Returns

int?

int

Exceptions

InvalidOperationException

FileGroupName(short?)

FILEGROUP_NAME (Transact-SQL)

This function returns the filegroup name for the specified filegroup identification (ID) number.

[Sql.Function("SqlServer", "FILEGROUP_Name", ServerSideOnly = true)]
public static string? FileGroupName(short? filegroup_id)

Parameters

filegroup_id short?

The filegroup ID number whose filegroup name FILEGROUP_NAME will return. filegroup_id has a smallint data type.

Returns

string

nvarchar(128)

Exceptions

InvalidOperationException

FileGroupProperty(string?, FileGroupPropertyName)

FILEGROUPPROPERTY (Transact-SQL)

This function returns the filegroup property value for a specified name and filegroup value.

[Sql.Extension("SqlServer", "FILEGROUPPROPERTY", ServerSideOnly = true, BuilderType = typeof(SqlFn.PropertyBuilder<SqlFn.FileGroupPropertyName>))]
public static int? FileGroupProperty(string? filegroup_name, SqlFn.FileGroupPropertyName property)

Parameters

filegroup_name string

An expression of type sysname that represents the filegroup name for which FILEGROUPPROPERTY returns the named property information.

property SqlFn.FileGroupPropertyName

An expression of type varchar(128) that returns the name of the filegroup property.

Returns

int?

int

Exceptions

InvalidOperationException

FileID(string?)

FILE_ID (Transact-SQL)

For the given logical name for a component file of the current database, this function returns the file identification (ID) number.

[Sql.Function("SqlServer", "FILE_ID", ServerSideOnly = true)]
public static short? FileID(string? file_name)

Parameters

file_name string

An expression of type sysname, representing the logical name of the file whose file ID value FILE_ID will return.

Returns

short?

smallint

Exceptions

InvalidOperationException

FileIDEx(string?)

FILE_IDEX (Transact-SQL)

This function returns the file identification (ID) number for the specified logical name of a data, log, or full-text file of the current database.

[Sql.Function("SqlServer", "FILE_IDEX", ServerSideOnly = true)]
public static int? FileIDEx(string? file_name)

Parameters

file_name string

An expression of type sysname that returns the file ID value 'FILE_IDEX' for the name of the file.

Returns

int?

int

Exceptions

InvalidOperationException

FileName(int?)

FILE_NAME (Transact-SQL)

This function returns the logical file name for a given file identification (ID) number.

[Sql.Function("SqlServer", "FILE_NAME", ServerSideOnly = true)]
public static string? FileName(int? file_id)

Parameters

file_id int?

The file identification number whose file name FILE_NAME will return. file_id has an int data type.

Returns

string

nvarchar(128)

Exceptions

InvalidOperationException

FileProperty(string?, FilePropertyName)

FILEPROPERTY (Transact-SQL)

Returns the specified file name property value when a file name in the current database and a property name are specified. Returns NULL for files that are not in the current database.

[Sql.Extension("SqlServer", "FILEPROPERTY", ServerSideOnly = true, BuilderType = typeof(SqlFn.PropertyBuilder<SqlFn.FilePropertyName>))]
public static int? FileProperty(string? file_name, SqlFn.FilePropertyName property)

Parameters

file_name string

Is an expression that contains the name of the file associated with the current database for which to return property information. file_name is nchar(128).

property SqlFn.FilePropertyName

Is an expression that contains the name of the file property to return. property is varchar(128), and can be one of the following values.

Returns

int?

int

Exceptions

InvalidOperationException

FilePropertyEx(string?, FilePropertyExName)

FILEPROPERTYEX (Transact-SQL)

Returns the specified extended file property value when a file name in the current database and a property name are specified. Returns NULL for files that are not in the current database or for extended file properties that do not exist. Currently, extended file properties only apply to databases that are in Azure Blob storage.

[Sql.Extension("SqlServer", "FILEPROPERTYEX", ServerSideOnly = true, BuilderType = typeof(SqlFn.PropertyBuilder<SqlFn.FilePropertyExName>))]
public static object? FilePropertyEx(string? file_name, SqlFn.FilePropertyExName property)

Parameters

file_name string

Is an expression that contains the name of the file associated with the current database for which to return property information. file_name is nchar(128).

property SqlFn.FilePropertyExName

Is an expression that contains the name of the file property to return. property is varchar(128), and can be one of the following values.

Returns

object

sql_variant

Exceptions

InvalidOperationException

Floor<T>(T)

FLOOR (Transact-SQL)

Returns the largest integer less than or equal to the specified numeric expression.

[Sql.Function("SqlServer", "FLOOR", ServerSideOnly = true, IgnoreGenericParameters = true)]
public static T Floor<T>(T numeric_expression)

Parameters

numeric_expression T

An expression of the exact numeric or approximate numeric data type category, except for the bit data type.

Returns

T

Return values have the same type as numeric_expression.

Type Parameters

T

Exceptions

InvalidOperationException

Format(object?, string?)

FORMAT (Transact-SQL)

Returns a value formatted with the specified format and optional culture. Use the FORMAT function for locale-aware formatting of date/time and number values as strings. For general data type conversions, use CAST or CONVERT.

[Sql.Function("SqlServer", "FORMAT", ServerSideOnly = true)]
public static string? Format(object? value, string? format)

Parameters

value object

Expression of a supported data type to format. For a list of valid types, see the table in the following Remarks section.

format string

Returns

string

nvarchar or null

Exceptions

InvalidOperationException

FormatMessage(int, params object?[])

FORMATMESSAGE (Transact-SQL)

Constructs a message from an existing message in sys.messages or from a provided string. The functionality of FORMATMESSAGE resembles that of the RAISERROR statement. However, RAISERROR prints the message immediately, while FORMATMESSAGE returns the formatted message for further processing.

[Sql.Function("SqlServer", "FORMATMESSAGE", ServerSideOnly = true)]
public static string? FormatMessage(int msg_number, params object?[] param_values)

Parameters

msg_number int

Is the ID of the message stored in sys.messages. If msg_number is <= 13000, or if the message does not exist in sys.messages, NULL is returned.

param_values object[]

Is a parameter value for use in the message. Can be more than one parameter value. The values must be specified in the order in which the placeholder variables appear in the message. The maximum number of values is 20.

Returns

string

nvarchar

Exceptions

InvalidOperationException

FormatMessage(string, params object?[])

FORMATMESSAGE (Transact-SQL)

Constructs a message from an existing message in sys.messages or from a provided string. The functionality of FORMATMESSAGE resembles that of the RAISERROR statement. However, RAISERROR prints the message immediately, while FORMATMESSAGE returns the formatted message for further processing.

[Sql.Function("SqlServer", "FORMATMESSAGE", ServerSideOnly = true)]
public static string? FormatMessage(string msg_string, params object?[] param_values)

Parameters

msg_string string

Is a string enclosed in single quotes and containing parameter value placeholders. The error message can have a maximum of 2,047 characters. If the message contains 2,048 or more characters, only the first 2,044 are displayed and an ellipsis is added to indicate that the message has been truncated. Note that substitution parameters consume more characters than the output shows because of internal storage behavior.

param_values object[]

Is a parameter value for use in the message. Can be more than one parameter value. The values must be specified in the order in which the placeholder variables appear in the message. The maximum number of values is 20.

Returns

string

nvarchar

Exceptions

InvalidOperationException

FullTextCatalogProperty(string?, FullTextCatalogPropertyName)

FULLTEXTCATALOGPROPERTY (Transact-SQL)

Returns information about full-text catalog properties in SQL Server.

[Sql.Extension("SqlServer", "FULLTEXTCATALOGPROPERTY", ServerSideOnly = true, BuilderType = typeof(SqlFn.PropertyBuilder<SqlFn.FullTextCatalogPropertyName>))]
public static int? FullTextCatalogProperty(string? catalog_name, SqlFn.FullTextCatalogPropertyName property)

Parameters

catalog_name string

Is an expression containing the name of the full-text catalog.

property SqlFn.FullTextCatalogPropertyName

Is an expression containing the name of the full-text catalog property. The table lists the properties and provides descriptions of the information returned.

Returns

int?

int

Exceptions

InvalidOperationException

FullTextServiceProperty(FullTextServicePropertyName)

FULLTEXTSERVICEPROPERTY (Transact-SQL)

Returns information related to the properties of the Full-Text Engine. These properties can be set and retrieved by using sp_fulltext_service.

[Sql.Extension("SqlServer", "FULLTEXTSERVICEPROPERTY", ServerSideOnly = true, BuilderType = typeof(SqlFn.PropertyBuilder<SqlFn.FullTextServicePropertyName>))]
public static int? FullTextServiceProperty(SqlFn.FullTextServicePropertyName property)

Parameters

property SqlFn.FullTextServicePropertyName

Is an expression containing the name of the full-text service-level property. The table lists the properties and provides descriptions of the information returned.

Returns

int?

int

Exceptions

InvalidOperationException

GetAnsiNull()

GETANSINULL (Transact-SQL)

Returns the default nullability for the database for this session.

[Sql.Function("SqlServer", "GETANSINULL", ServerSideOnly = true)]
public static int? GetAnsiNull()

Returns

int?

int

Exceptions

InvalidOperationException

GetAnsiNull(string)

GETANSINULL (Transact-SQL)

Returns the default nullability for the database for this session.

[Sql.Function("SqlServer", "GETANSINULL", ServerSideOnly = true)]
public static int? GetAnsiNull(string database)

Parameters

database string

Is the name of the database for which to return nullability information. database is either char or nchar. If char, database is implicitly converted to nchar.

Returns

int?

int

Exceptions

InvalidOperationException

GetDate()

GETDATE (Transact-SQL)

Returns the current database system timestamp as a datetime value without the database time zone offset.

[Sql.Function("SqlServer", "GETDATE", ServerSideOnly = true)]
public static DateTime GetDate()

Returns

DateTime

datetime

Exceptions

InvalidOperationException

GetUtcDate()

GETUTCDATE (Transact-SQL)

Returns the current database system timestamp as a datetime value. The database time zone offset is not included. This value represents the current UTC time (Coordinated Universal Time). This value is derived from the operating system of the computer on which the instance of SQL Server is running.

[Sql.Function("SqlServer", "GETUTCDATE", ServerSideOnly = true)]
public static DateTime GetUtcDate()

Returns

DateTime

datetime

Exceptions

InvalidOperationException

HostID()

HOST_ID (Transact-SQL)

Returns the workstation identification number. The workstation identification number is the process ID (PID) of the application on the client computer that is connecting to SQL Server.

[Sql.Function("SqlServer", "HOST_ID", ServerSideOnly = true)]
public static string HostID()

Returns

string

char(10)

Exceptions

InvalidOperationException

HostName()

HOST_NAME (Transact-SQL)

Returns the workstation identification number. The workstation identification number is the process ID (PID) of the application on the client computer that is connecting to SQL Server.

[Sql.Function("SqlServer", "HOST_NAME", ServerSideOnly = true)]
public static string HostName()

Returns

string

nvarchar(128)

Exceptions

InvalidOperationException

IdentityCurrent(string)

IDENT_CURRENT (Transact-SQL)

Returns the last identity value generated for a specified table or view. The last identity value generated can be for any session and any scope.

[Sql.Function("SqlServer", "IDENT_CURRENT", ServerSideOnly = true)]
public static decimal IdentityCurrent(string table_or_view)

Parameters

table_or_view string

Is the name of the table or view whose identity value is returned. table_or_view is varchar, with no default.

Returns

decimal

numeric(@@MAXPRECISION, 0))

Exceptions

InvalidOperationException

IdentityIncrement(string)

IDENT_INCR (Transact-SQL)

Returns the increment value specified when creating a table or view's identity column.

[Sql.Function("SqlServer", "IDENT_INCR", ServerSideOnly = true)]
public static decimal IdentityIncrement(string table_or_view)

Parameters

table_or_view string

Is an expression specifying the table or view to check for a valid identity increment value. table_or_view can be a character string constant enclosed in quotation marks. It can also be a variable, a function, or a column name. table_or_view is char, nchar, varchar, or nvarchar.

Returns

decimal

numeric(@@MAXPRECISION, 0))

Exceptions

InvalidOperationException

IdentitySeed(string)

IDENT_SEED (Transact-SQL)

Returns the original seed value specified when creating an identity column in a table or a view. Changing the current value of an identity column by using DBCC CHECKIDENT doesn't change the value returned by this function.

[Sql.Function("SqlServer", "IDENT_SEED", ServerSideOnly = true)]
public static decimal IdentitySeed(string table_or_view)

Parameters

table_or_view string

Is an expression specifying the table or view to check for a valid identity increment value. table_or_view can be a character string constant enclosed in quotation marks. It can also be a variable, a function, or a column name. table_or_view is char, nchar, varchar, or nvarchar.

Returns

decimal

numeric(@@MAXPRECISION, 0))

Exceptions

InvalidOperationException

Iif<T>(bool?, T, T)

IIF (Transact-SQL)

Returns one of two values, depending on whether the Boolean expression evaluates to true or false in SQL Server.

[Sql.Function("SqlServer", "IIF", ServerSideOnly = true, IgnoreGenericParameters = true)]
public static T Iif<T>(bool? boolean_expression, T true_value, T false_value)

Parameters

boolean_expression bool?

A valid Boolean expression.

true_value T

Value to return if boolean_expression evaluates to true.

false_value T

Value to return if boolean_expression evaluates to false.

Returns

T

Returns the data type with the highest precedence from the types in true_value and false_value.

Type Parameters

T

Exceptions

InvalidOperationException

IndexColumn(string, int, int)

INDEX_COL (Transact-SQL)

Returns the indexed column name. Returns NULL for XML indexes.

[Sql.Function("SqlServer", "INDEX_COL", ServerSideOnly = true)]
public static string? IndexColumn(string table_or_view, int index_id, int key_id)

Parameters

table_or_view string

Is the name of the table or indexed view. table_or_view_name must be delimited by single quotation marks and can be fully qualified by database name and schema name.

index_id int

Is the ID of the index. index_ID is int.

key_id int

Is the index key column position. key_ID is int.

Returns

string

nvarchar(128)

Exceptions

InvalidOperationException

IndexKeyProperty(int?, int?, int?, IndexKeyPropertyName)

INDEXKEY_PROPERTY (Transact-SQL)

Returns information about the index key. Returns NULL for XML indexes.

[Sql.Extension("SqlServer", "INDEXKEY_PROPERTY", ServerSideOnly = true, BuilderType = typeof(SqlFn.PropertyBuilder<SqlFn.IndexKeyPropertyName>))]
public static int? IndexKeyProperty(int? object_ID, int? index_ID, int? key_ID, SqlFn.IndexKeyPropertyName property)

Parameters

object_ID int?

Is the object identification number of the table or indexed view. object_ID is int.

index_ID int?

Is the index identification number. index_ID is int.

key_ID int?

Is the index key column position. key_ID is int.

property SqlFn.IndexKeyPropertyName

Is the name of the property for which information will be returned. property is a character string and can be one of the following values.

Returns

int?

int

Exceptions

InvalidOperationException

IndexProperty(int?, string?, IndexPropertyName)

INDEXPROPERTY (Transact-SQL)

Returns information about the index key. Returns NULL for XML indexes.

[Sql.Extension("SqlServer", "INDEXPROPERTY", ServerSideOnly = true, BuilderType = typeof(SqlFn.PropertyBuilder<SqlFn.IndexPropertyName>))]
public static int? IndexProperty(int? object_ID, string? index_or_statistics_name, SqlFn.IndexPropertyName property)

Parameters

object_ID int?

Is an expression that contains the object identification number of the table or indexed view for which to provide index property information. object_ID is int.

index_or_statistics_name string

Is an expression that contains the name of the index or statistics for which to return property information. index_or_statistics_name is nvarchar(128).

property SqlFn.IndexPropertyName

Is an expression that contains the name of the database property to return. property is varchar(128), and can be one of these values.

Returns

int?

int

Exceptions

InvalidOperationException

IsDate(string)

ISDATE (Transact-SQL)

Returns 1 if the expression is a valid datetime value; otherwise, 0. ISDATE returns 0 if the expression is a datetime2 value.

[Sql.Function("SqlServer", "ISDATE", ServerSideOnly = true)]
public static int IsDate(string expression)

Parameters

expression string

Returns

int

int

Exceptions

InvalidOperationException

IsJson(string?)

ISJSON (Transact-SQL)

Tests whether a string contains valid JSON.

[Sql.Function("SqlServer", "ISJSON", ServerSideOnly = true)]
public static bool? IsJson(string? expression)

Parameters

expression string

The string to test.

Returns

bool?

Returns 1 if the string contains valid JSON; otherwise, returns 0. Returns null if expression is null.

Exceptions

InvalidOperationException

IsNull<T>(T, T)

ISNULL (Transact-SQL)

Replaces NULL with the specified replacement value.

[Sql.Function("SqlServer", "ISNULL", ServerSideOnly = true, IgnoreGenericParameters = true)]
public static T IsNull<T>(T check_expression, T replacement_value)

Parameters

check_expression T

Is the expression to be checked for NULL. check_expression can be of any type.

replacement_value T

Is the expression to be returned if check_expression is NULL. replacement_value must be of a type that is implicitly convertible to the type of check_expression.

Returns

T

Returns the same type as check_expression. If a literal NULL is provided as check_expression, returns the datatype of the replacement_value. If a literal NULL is provided as check_expression and no replacement_value is provided, returns an int.

Type Parameters

T

Exceptions

InvalidOperationException

IsNumeric<T>(T)

ISNUMERIC (Transact-SQL)

Determines whether an expression is a valid numeric type.

[Sql.Function("SqlServer", "ISNUMERIC", ServerSideOnly = true, IgnoreGenericParameters = true)]
public static int IsNumeric<T>(T expression)

Parameters

expression T

Is the expression to be evaluated.

Returns

int

int

Type Parameters

T

Exceptions

InvalidOperationException

JsonModify(string?, string, string)

JSON_MODIFY (Transact-SQL)

Updates the value of a property in a JSON string and returns the updated JSON string.

[Sql.Function("SqlServer", "JSON_MODIFY", ServerSideOnly = true)]
public static string? JsonModify(string? expression, string path, string newValue)

Parameters

expression string

An expression. Typically the name of a variable or a column that contains JSON text.

path string

A JSON path expression that specifies the property to update.

newValue string

The new value for the property specified by path. The new value must be a [n]varchar or text.

Returns

string

Returns the updated value of expression as properly formatted JSON text.

Exceptions

InvalidOperationException

JsonQuery(string?, string)

JSON_QUERY (Transact-SQL)

Extracts an object or an array from a JSON string.

[Sql.Function("SqlServer", "JSON_QUERY", ServerSideOnly = true)]
public static string? JsonQuery(string? expression, string path)

Parameters

expression string

An expression. Typically the name of a variable or a column that contains JSON text.

path string

A JSON path that specifies the property to extract.

Returns

string

Returns a JSON fragment of type nvarchar(max). The collation of the returned value is the same as the collation of the input expression.

Exceptions

InvalidOperationException

JsonValue(string?, string)

JSON_VALUE (Transact-SQL)

Extracts a scalar value from a JSON string.

[Sql.Function("SqlServer", "JSON_VALUE", ServerSideOnly = true)]
public static string? JsonValue(string? expression, string path)

Parameters

expression string

An expression. Typically the name of a variable or a column that contains JSON text.

path string

A JSON path that specifies the property to extract.

Returns

string

Returns a single text value of type nvarchar(4000). The collation of the returned value is the same as the collation of the input expression.

Exceptions

InvalidOperationException

Left(string?, int?)

LEFT (Transact-SQL)

Returns the left part of a character string with the specified number of characters.

[Sql.Function("SqlServer", "LEFT", ServerSideOnly = true)]
public static string? Left(string? character_expression, int? integer_expression)

Parameters

character_expression string

Is an expression of character or binary data. character_expression can be a constant, variable, or column. character_expression can be of any data type, except text or ntext, that can be implicitly converted to varchar or nvarchar. Otherwise, use the CAST function to explicitly convert character_expression.

integer_expression int?

Is a positive integer that specifies how many characters of the character_expression will be returned. If integer_expression is negative, an error is returned. If integer_expression is type bigint and contains a large value, character_expression must be of a large data type such as varchar(max). The integer_expression parameter counts a UTF-16 surrogate character as one character.

Returns

string

Returns varchar when character_expression is a non-Unicode character data type. Returns nvarchar when character_expression is a Unicode character data type.

Exceptions

InvalidOperationException

LeftTrim(string?)

LTRIM (Transact-SQL)

Returns a character expression after it removes leading blanks.

[Sql.Function("SqlServer", "LTRIM", ServerSideOnly = true)]
public static string? LeftTrim(string? character_expression)

Parameters

character_expression string

Is the string expression of character or binary data. character_expression can be a constant, variable, or column. character_expression must be of a data type that is implicitly convertible to varchar.

Returns

string

varchar or nvarchar

Exceptions

InvalidOperationException

Len(string?)

LEN (Transact-SQL)

Returns the number of characters of the specified string expression, excluding trailing spaces.

[Sql.Function("SqlServer", "LEN", ServerSideOnly = true)]
public static int? Len(string? character_expression)

Parameters

character_expression string

Is the string expression to be evaluated. character_expression can be a constant, variable, or column of either character or binary data.

Returns

int?

bigint if expression is of the varchar(max), nvarchar(max) or varbinary(max) data types; otherwise, int.

Exceptions

InvalidOperationException

LenBig(string?)

LEN (Transact-SQL)

Returns the number of characters of the specified string expression, excluding trailing spaces.

[Sql.Function("SqlServer", "LEN", ServerSideOnly = true)]
public static long? LenBig(string? character_expression)

Parameters

character_expression string

Is the string expression to be evaluated. character_expression can be a constant, variable, or column of either character or binary data.

Returns

long?

bigint if expression is of the varchar(max), nvarchar(max) or varbinary(max) data types; otherwise, int.

Exceptions

InvalidOperationException

Log10<T>(T)

LOG10 (Transact-SQL)

Returns the base-10 logarithm of the specified float expression.

[Sql.Function("SqlServer", "LOG", ServerSideOnly = true, IgnoreGenericParameters = true)]
public static T Log10<T>(T float_expression)

Parameters

float_expression T

Is an expression of type float or of a type that can be implicitly converted to float.

Returns

T

float

Type Parameters

T

Exceptions

InvalidOperationException

Log<T>(T)

LOG (Transact-SQL)

Returns the natural logarithm of the specified float expression in SQL Server.

[Sql.Function("SqlServer", "LOG", ServerSideOnly = true, IgnoreGenericParameters = true)]
public static T Log<T>(T float_expression)

Parameters

float_expression T

Is an expression of type float or of a type that can be implicitly converted to float.

Returns

T

float

Type Parameters

T

Exceptions

InvalidOperationException

Log<T>(T, int)

LOG (Transact-SQL)

Returns the natural logarithm of the specified float expression in SQL Server.

[Sql.Function("SqlServer", "LOG", ServerSideOnly = true, IgnoreGenericParameters = true)]
public static T Log<T>(T float_expression, int @base)

Parameters

float_expression T

Is an expression of type float or of a type that can be implicitly converted to float.

base int

Optional integer argument that sets the base for the logarithm.

Returns

T

float

Type Parameters

T

Exceptions

InvalidOperationException

Lower(string?)

LOWER (Transact-SQL)

Returns a character expression after converting uppercase character data to lowercase.

[Sql.Function("SqlServer", "LOWER", ServerSideOnly = true)]
public static string? Lower(string? character_expression)

Parameters

character_expression string

Is the string expression of character or binary data. character_expression can be a constant, variable, or column. character_expression must be of a data type that is implicitly convertible to varchar.

Returns

string

varchar or nvarchar

Exceptions

InvalidOperationException

MinActiveRowVersion()

MIN_ACTIVE_ROWVERSION (Transact-SQL)

Returns the workstation identification number. The workstation identification number is the process ID (PID) of the application on the client computer that is connecting to SQL Server.

[Sql.Function("SqlServer", "MIN_ACTIVE_ROWVERSION", ServerSideOnly = true)]
public static byte[] MinActiveRowVersion()

Returns

byte[]

Returns a binary(8) value.

Exceptions

InvalidOperationException

Month(DateTimeOffset?)

MONTH (Transact-SQL)

This function returns an integer that represents the day (day of the month) of the specified date.

[Sql.Function("SqlServer", "MONTH", ServerSideOnly = true)]
public static int? Month(DateTimeOffset? date)

Parameters

date DateTimeOffset?

Returns

int?

int

Exceptions

InvalidOperationException

Month(DateTime?)

MONTH (Transact-SQL)

This function returns an integer that represents the day (day of the month) of the specified date.

[Sql.Function("SqlServer", "MONTH", ServerSideOnly = true)]
public static int? Month(DateTime? date)

Parameters

date DateTime?

Returns

int?

int

Exceptions

InvalidOperationException

Month(string?)

MONTH (Transact-SQL)

Returns an integer that represents the month of the specified date.

[Sql.Function("SqlServer", "MONTH", ServerSideOnly = true)]
public static int? Month(string? date)

Parameters

date string

Returns

int?

int

Exceptions

InvalidOperationException

NChar(int?)

NCHAR (Transact-SQL)

Returns the Unicode character with the specified integer code, as defined by the Unicode standard.

[Sql.Function("SqlServer", "NCHAR", ServerSideOnly = true)]
public static char? NChar(int? integer_expression)

Parameters

integer_expression int?

When the collation of the database does not contain the Supplementary Character (SC) flag, this is a positive integer from 0 through 65535 (0 through 0xFFFF). If a value outside this range is specified, NULL is returned.

Returns

char?

nchar(1) when the default database collation does not support supplementary characters. nvarchar(2) when the default database collation supports supplementary characters.

Exceptions

InvalidOperationException

NewID()

NEWID (Transact-SQL)

Creates a unique value of type uniqueidentifier.

[Sql.Function("SqlServer", "NEWID", ServerSideOnly = true)]
public static Guid NewID()

Returns

Guid

uniqueidentifier

Exceptions

InvalidOperationException

NextValueFor(string)

NEXT VALUE FOR (Transact-SQL)

Generates a sequence number from the specified sequence object.

[Sql.Extension("SqlServer", "NEXT VALUE FOR {sequence_name}", ServerSideOnly = true, BuilderType = typeof(SqlFn.NextValueForBuilder))]
public static object? NextValueFor(string sequence_name)

Parameters

sequence_name string

The name of the sequence object that generates the number.

Returns

object

Returns a number using the type of the sequence.

Exceptions

InvalidOperationException

NextValueForOver(string)

NEXT VALUE FOR (Transact-SQL)

Generates a sequence number from the specified sequence object.

[Sql.Extension("SqlServer", "NEXT VALUE FOR {sequence_name} OVER ({order_by_clause})", ServerSideOnly = true, BuilderType = typeof(SqlFn.NextValueForBuilder), TokenName = "function", ChainPrecedence = 1, IsWindowFunction = true)]
public static AnalyticFunctions.INeedsOrderByOnly<object?> NextValueForOver(string sequence_name)

Parameters

sequence_name string

The name of the sequence object that generates the number.

Returns

AnalyticFunctions.INeedsOrderByOnly<object>

Returns a number using the type of the sequence.

Exceptions

InvalidOperationException

ObjectDefinition(int?)

OBJECT_DEFINITION (Transact-SQL)

Returns the Transact-SQL source text of the definition of a specified object.

[Sql.Function("SqlServer", "OBJECT_DEFINITION", ServerSideOnly = true)]
public static string? ObjectDefinition(int? object_id)

Parameters

object_id int?

Is the ID of the object to be used. object_id is int, and assumed to represent an object in the current database context.

Returns

string

nvarchar(max)

Exceptions

InvalidOperationException

ObjectID(string)

OBJECT_ID (Transact-SQL)

Returns the database object identification number of a schema-scoped object.

[Sql.Function("SqlServer", "OBJECT_ID", ServerSideOnly = true)]
public static int? ObjectID(string object_name)

Parameters

object_name string

Is the object to be used. object_name is either varchar or nvarchar. If object_name is varchar, it is implicitly converted to nvarchar. Specifying the database and schema names is optional.

Returns

int?

int

Exceptions

InvalidOperationException

ObjectID(string, string)

OBJECT_ID (Transact-SQL)

Returns the database object identification number of a schema-scoped object.

[Sql.Function("SqlServer", "OBJECT_ID", ServerSideOnly = true)]
public static int? ObjectID(string object_name, string object_type)

Parameters

object_name string

Is the object to be used. object_name is either varchar or nvarchar. If object_name is varchar, it is implicitly converted to nvarchar. Specifying the database and schema names is optional.

object_type string

Is the schema-scoped object type. object_type is either varchar or nvarchar. If object_type is varchar, it is implicitly converted to nvarchar. For a list of object types, see the type column in sys.objects (Transact-SQL).

Returns

int?

int

Exceptions

InvalidOperationException

ObjectName(int?)

OBJECT_NAME (Transact-SQL)

Returns the database object name for schema-scoped objects. For a list of schema-scoped objects, see sys.objects (Transact-SQL).

[Sql.Function("SqlServer", "OBJECT_NAME", ServerSideOnly = true)]
public static string? ObjectName(int? object_id)

Parameters

object_id int?

Is the ID of the object to be used. object_id is int and is assumed to be a schema-scoped object in the specified database, or in the current database context.

Returns

string

sysname

Exceptions

InvalidOperationException

ObjectName(int?, int?)

OBJECT_NAME (Transact-SQL)

Returns the database object name for schema-scoped objects. For a list of schema-scoped objects, see sys.objects (Transact-SQL).

[Sql.Function("SqlServer", "OBJECT_NAME", ServerSideOnly = true)]
public static string? ObjectName(int? object_id, int? database_id)

Parameters

object_id int?

Is the ID of the object to be used. object_id is int and is assumed to be a schema-scoped object in the specified database, or in the current database context.

database_id int?

Is the ID of the database where the object is to be looked up. database_id is int.

Returns

string

sysname

Exceptions

InvalidOperationException

ObjectProperty(int?, ObjectPropertyName)

OBJECTPROPERTY (Transact-SQL)

Returns information about schema-scoped objects in the current database. For a list of schema-scoped objects, see sys.objects (Transact-SQL). This function cannot be used for objects that are not schema-scoped, such as data definition language (DDL) triggers and event notifications.

[Sql.Extension("SqlServer", "OBJECTPROPERTY", ServerSideOnly = true, BuilderType = typeof(SqlFn.PropertyBuilder<SqlFn.ObjectPropertyName>))]
public static int? ObjectProperty(int? id, SqlFn.ObjectPropertyName property)

Parameters

id int?

Is an expression that represents the ID of the object in the current database. id is int and is assumed to be a schema-scoped object in the current database context.

property SqlFn.ObjectPropertyName

Is an expression that represents the information to be returned for the object specified by id. property can be one of the following values.

Returns

int?

int

Exceptions

InvalidOperationException

ObjectPropertyEx(int?, ObjectPropertyExName)

OBJECTPROPERTYEX (Transact-SQL)

Returns information about schema-scoped objects in the current database. For a list of these objects, see sys.objects (Transact-SQL). OBJECTPROPERTYEX cannot be used for objects that are not schema-scoped, such as data definition language (DDL) triggers and event notifications.

[Sql.Extension("SqlServer", "OBJECTPROPERTYEX", ServerSideOnly = true, BuilderType = typeof(SqlFn.PropertyBuilder<SqlFn.ObjectPropertyExName>))]
public static object? ObjectPropertyEx(int? id, SqlFn.ObjectPropertyExName property)

Parameters

id int?

Is an expression that represents the ID of the object in the current database. id is int and is assumed to be a schema-scoped object in the current database context.

property SqlFn.ObjectPropertyExName

Is an expression that contains the information to be returned for the object specified by id. The return type is sql_variant. The following table shows the base data type for each property value.

Returns

object

sql_variant

Exceptions

InvalidOperationException

ObjectSchemaName(int?)

OBJECT_SCHEMA_NAME (Transact-SQL)

Returns the database schema name for schema-scoped objects. For a list of schema-scoped objects, see sys.objects (Transact-SQL).

[Sql.Function("SqlServer", "OBJECT_SCHEMA_NAME", ServerSideOnly = true)]
public static string? ObjectSchemaName(int? object_id)

Parameters

object_id int?

Is the ID of the object to be used. object_id is int and is assumed to be a schema-scoped object in the specified database, or in the current database context.

Returns

string

sysname

Exceptions

InvalidOperationException

ObjectSchemaName(int?, int?)

OBJECT_SCHEMA_NAME (Transact-SQL)

Returns the database schema name for schema-scoped objects. For a list of schema-scoped objects, see sys.objects (Transact-SQL).

[Sql.Function("SqlServer", "OBJECT_SCHEMA_NAME", ServerSideOnly = true)]
public static string? ObjectSchemaName(int? object_id, int? database_id)

Parameters

object_id int?

Is the ID of the object to be used. object_id is int and is assumed to be a schema-scoped object in the specified database, or in the current database context.

database_id int?

Is the ID of the database where the object is to be looked up. database_id is int.

Returns

string

sysname

Exceptions

InvalidOperationException

OpenJson(string?)

OPENJSON (Transact-SQL)

A table-valued function that parses JSON text and returns objects and properties from the JSON input as rows and columns.

[Sql.TableExpression("OPENJSON({2}) {1}")]
public static IQueryable<SqlFn.JsonData> OpenJson(string? json)

Parameters

json string

An expression. Typically the name of a variable or a column that contains JSON text.

Returns

IQueryable<SqlFn.JsonData>

Returns a rowset view over the elements of a JSON object or array.

Remarks

Only available on SQL Server 2016 or later, and compatibility mode for the database must be set to 130 or higher

Exceptions

InvalidOperationException

OpenJson(string?, string)

OPENJSON (Transact-SQL)

A table-valued function that parses JSON text and returns objects and properties from the JSON input as rows and columns.

[Sql.TableExpression("OPENJSON({2}, {3}) {1}")]
public static IQueryable<SqlFn.JsonData> OpenJson(string? json, string path)

Parameters

json string

An expression. Typically the name of a variable or a column that contains JSON text.

path string

A JSON path expression that specifies the property to query.

Returns

IQueryable<SqlFn.JsonData>

Returns a rowset view over the elements of a JSON object or array.

Remarks

Only available on SQL Server 2016 or later, and compatibility mode for the database must be set to 130 or higher

Exceptions

InvalidOperationException

OriginalDbName()

ORIGINAL_DB_NAME (Transact-SQL)

Returns the database name specified by the user in the database connection string. This database is specified by using the sqlcmd-d option (USE database). It can also be specified with the Open Database Connectivity (ODBC) data source expression (initial catalog = databasename).

This database is different from the default user database.

[Sql.Function("SqlServer", "ORIGINAL_DB_NAME", ServerSideOnly = true)]
public static string? OriginalDbName()

Returns

string

Exceptions

InvalidOperationException

PI()

PI (Transact-SQL)

Returns the constant value of PI.

[Sql.Function("SqlServer", "PI", ServerSideOnly = true)]
public static double PI()

Returns

double

float

Exceptions

InvalidOperationException

ParseName(string?, int)

PARSENAME (Transact-SQL)

Returns the database schema name for schema-scoped objects. For a list of schema-scoped objects, see sys.objects (Transact-SQL).

[Sql.Function("SqlServer", "PARSENAME", ServerSideOnly = true)]
public static string? ParseName(string? object_name, int object_piece)

Parameters

object_name string

Is the parameter that holds the name of the object for which to retrieve the specified object part. This parameter is an optionally-qualified object name. If all parts of the object name are qualified, this name can have four parts: the server name, the database name, the schema name, and the object name. Each part of the 'object_name' string is type sysname which is equivalent to nvarchar(128) or 256 bytes. If any part of the string exceeds 256 bytes, PARSENAME will return NULL for that part as it is not a valid sysname.

object_piece int

Is the object part to return. object_piece is of type int, and can have these values:

  • 1 = Object name
  • 2 = Schema name
  • 3 = Database name
  • 4 = Server name

Returns

string

sysname

Exceptions

InvalidOperationException

Parse<T>(string)

PARSE (Transact-SQL)

Returns the result of an expression, translated to the requested data type in SQL Server.

[Sql.Expression("SqlServer", "PARSE({0} as {1})", ServerSideOnly = true)]
public static T Parse<T>(string string_value)

Parameters

string_value string

nvarchar(4000) value representing the formatted value to parse into the specified data type.

Returns

T

Returns the result of the expression, translated to the requested data type.

Type Parameters

T

Exceptions

InvalidOperationException

Parse<T>(string, SqlType<T>)

PARSE (Transact-SQL)

Returns the result of an expression, translated to the requested data type in SQL Server.

[Sql.Extension("SqlServer", "PARSE({string_value} as {data_type})", ServerSideOnly = true, BuilderType = typeof(SqlFn.DataTypeBuilder))]
public static T Parse<T>(string string_value, SqlType<T> data_type)

Parameters

string_value string

nvarchar(4000) value representing the formatted value to parse into the specified data type.

data_type SqlType<T>

Literal value representing the data type requested for the result.

Returns

T

Returns the result of the expression, translated to the requested data type.

Type Parameters

T

Exceptions

InvalidOperationException

Parse<T>(string, SqlType<T>, string)

PARSE (Transact-SQL)

Returns the result of an expression, translated to the requested data type in SQL Server.

[Sql.Extension("SqlServer", "PARSE({string_value} as {data_type} USING {culture})", ServerSideOnly = true, BuilderType = typeof(SqlFn.DataTypeBuilder))]
public static T Parse<T>(string string_value, SqlType<T> data_type, string culture)

Parameters

string_value string

nvarchar(4000) value representing the formatted value to parse into the specified data type.

data_type SqlType<T>

Literal value representing the data type requested for the result.

culture string

Optional string that identifies the culture in which string_value is formatted.

Returns

T

Returns the result of the expression, translated to the requested data type.

Type Parameters

T

Exceptions

InvalidOperationException

Parse<T>(string, Func<SqlType<T>>)

PARSE (Transact-SQL)

Returns the result of an expression, translated to the requested data type in SQL Server.

[Sql.Extension("SqlServer", "PARSE({string_value} as {data_type})", ServerSideOnly = true, BuilderType = typeof(SqlFn.DataTypeBuilder))]
public static T Parse<T>(string string_value, Func<SqlType<T>> data_type)

Parameters

string_value string

nvarchar(4000) value representing the formatted value to parse into the specified data type.

data_type Func<SqlType<T>>

Literal value representing the data type requested for the result.

Returns

T

Returns the result of the expression, translated to the requested data type.

Type Parameters

T

Exceptions

InvalidOperationException

Parse<T>(string, Func<SqlType<T>>, string)

PARSE (Transact-SQL)

Returns the result of an expression, translated to the requested data type in SQL Server.

[Sql.Extension("SqlServer", "PARSE({string_value} as {data_type} USING {culture})", ServerSideOnly = true, BuilderType = typeof(SqlFn.DataTypeBuilder))]
public static T Parse<T>(string string_value, Func<SqlType<T>> data_type, string culture)

Parameters

string_value string

nvarchar(4000) value representing the formatted value to parse into the specified data type.

data_type Func<SqlType<T>>

Literal value representing the data type requested for the result.

culture string

Optional string that identifies the culture in which string_value is formatted.

Returns

T

Returns the result of the expression, translated to the requested data type.

Type Parameters

T

Exceptions

InvalidOperationException

Parse<T>(string, string)

PARSE (Transact-SQL)

Returns the result of an expression, translated to the requested data type in SQL Server.

[Sql.Expression("SqlServer", "PARSE({0} as {2} USING {1})", ServerSideOnly = true)]
public static T Parse<T>(string string_value, string culture)

Parameters

string_value string

nvarchar(4000) value representing the formatted value to parse into the specified data type.

culture string

Optional string that identifies the culture in which string_value is formatted.

Returns

T

Returns the result of the expression, translated to the requested data type.

Type Parameters

T

Exceptions

InvalidOperationException

PatIndex(string?, string?)

PATINDEX (Transact-SQL)

Returns the starting position of the first occurrence of a pattern in a specified expression, or zeros if the pattern is not found, on all valid text and character data types.

[Sql.Function("SqlServer", "PATINDEX", ServerSideOnly = true)]
public static int? PatIndex(string? pattern, string? expression)

Parameters

pattern string

Is a character expression that contains the sequence to be found. Wildcard characters can be used; however, the % character must come before and follow pattern (except when you search for first or last characters). pattern is an expression of the character string data type category. pattern is limited to 8000 characters.

expression string

Is an expression, typically a column that is searched for the specified pattern. expression is of the character string data type category.

Returns

int?

bigint if expression is of the varchar(max) or nvarchar(max) data types; otherwise int.

Exceptions

InvalidOperationException

PatIndexBig(string?, string?)

PATINDEX (Transact-SQL)

Returns the starting position of the first occurrence of a pattern in a specified expression, or zeros if the pattern is not found, on all valid text and character data types.

[Sql.Function("SqlServer", "PATINDEX", ServerSideOnly = true)]
public static long? PatIndexBig(string? pattern, string? expression)

Parameters

pattern string

Is a character expression that contains the sequence to be found. Wildcard characters can be used; however, the % character must come before and follow pattern (except when you search for first or last characters). pattern is an expression of the character string data type category. pattern is limited to 8000 characters.

expression string

Is an expression, typically a column that is searched for the specified pattern. expression is of the character string data type category.

Returns

long?

bigint if expression is of the varchar(max) or nvarchar(max) data types; otherwise int.

Exceptions

InvalidOperationException

Power<T>(T, T)

POWER (Transact-SQL)

Returns the base-10 logarithm of the specified float expression.

[Sql.Function("SqlServer", "POWER", ServerSideOnly = true, IgnoreGenericParameters = true)]
public static T Power<T>(T float_expression, T y)

Parameters

float_expression T

Is an expression of type float or of a type that can be implicitly converted to float.

y T

Is the power to which to raise float_expression. y can be an expression of the exact numeric or approximate numeric data type category, except for the bit data type.

Returns

T

float

Type Parameters

T

Exceptions

InvalidOperationException

PublishingServerName()

PUBLISHINGSERVERNAME (Transact-SQL)

Returns the name of the originating Publisher for a published database participating in a database mirroring session. This function is executed at a Publisher instance of SQL Server on the publication database. Use it to determine the original Publisher of the published database.

[Sql.Function("SqlServer", "PUBLISHINGSERVERNAME", ServerSideOnly = true)]
public static string? PublishingServerName()

Returns

string

nvarchar

Exceptions

InvalidOperationException

QuoteName(string?)

QUOTENAME (Transact-SQL)

Returns a Unicode string with the delimiters added to make the input string a valid SQL Server delimited identifier.

[Sql.Function("SqlServer", "QUOTENAME", ServerSideOnly = true)]
public static string? QuoteName(string? character_string)

Parameters

character_string string

Is a string of Unicode character data. character_string is sysname and is limited to 128 characters. Inputs greater than 128 characters return NULL.

Returns

string

nvarchar(258)

Exceptions

InvalidOperationException

QuoteName(string?, string?)

QUOTENAME (Transact-SQL)

Returns a Unicode string with the delimiters added to make the input string a valid SQL Server delimited identifier.

[Sql.Function("SqlServer", "QUOTENAME", ServerSideOnly = true)]
public static string? QuoteName(string? character_string, string? quote_character)

Parameters

character_string string

Is a string of Unicode character data. character_string is sysname and is limited to 128 characters. Inputs greater than 128 characters return NULL.

quote_character string

Is a one-character string to use as the delimiter. Can be a single quotation mark ( ' ), a left or right bracket ( [] ), a double quotation mark ( " ), a left or right parenthesis ( () ), a greater than or less than sign ( >< ), a left or right brace ( {} ) or a backtick ( ` ). NULL returns if an unacceptable character is supplied. If quote_character is not specified, brackets are used.

Returns

string

nvarchar(258)

Exceptions

InvalidOperationException

Radians<T>(T)

RADIANS (Transact-SQL)

Returns radians when a numeric expression, in degrees, is entered.

[Sql.Function("SqlServer", "RADIANS", ServerSideOnly = true, IgnoreGenericParameters = true)]
public static T Radians<T>(T numeric_expression)

Parameters

numeric_expression T

An expression of the exact numeric or approximate numeric data type category, except for the bit data type.

Returns

T

Return values have the same type as numeric_expression.

Type Parameters

T

Exceptions

InvalidOperationException

Random()

RAND (Transact-SQL)

Returns a pseudo-random float value from 0 through 1, exclusive.

[Sql.Function("SqlServer", "RAND", ServerSideOnly = true, IgnoreGenericParameters = true)]
public static double Random()

Returns

double

float

Exceptions

InvalidOperationException

Random(int)

RAND (Transact-SQL)

Returns a pseudo-random float value from 0 through 1, exclusive.

[Sql.Function("SqlServer", "RAND", ServerSideOnly = true, IgnoreGenericParameters = true)]
public static double Random(int seed)

Parameters

seed int

Returns

double

float

Exceptions

InvalidOperationException

Replace(string?, string?, string?)

REPLACE (Transact-SQL)

Replaces all occurrences of a specified string value with another string value.

[Sql.Function("SqlServer", "REPLACE", ServerSideOnly = true)]
public static string? Replace(string? string_expression, string? string_pattern, string? string_replacement)

Parameters

string_expression string

Is the string expression to be searched. string_expression can be of a character or binary data type.

string_pattern string

Is the substring to be found. string_pattern can be of a character or binary data type. string_pattern must not exceed the maximum number of bytes that fits on a page. If string_pattern is an empty string (''), string_expression is returned unchanged.

string_replacement string

Is the replacement string. string_replacement can be of a character or binary data type.

Returns

string

Returns nvarchar if one of the input arguments is of the nvarchar data type; otherwise, REPLACE returns varchar. Returns NULL if any one of the arguments is NULL.

Exceptions

InvalidOperationException

Replicate(byte[]?, int?)

REPLICATE (Transact-SQL)

Repeats a string value a specified number of times.

[Sql.Function("SqlServer", "REPLICATE", ServerSideOnly = true)]
public static string? Replicate(byte[]? string_expression, int? integer_expression)

Parameters

string_expression byte[]

Is an expression of a character string or binary data type.

integer_expression int?

Is an expression of any integer type, including bigint. If integer_expression is negative, NULL is returned.

Returns

string

Returns the same type as string_expression.

Exceptions

InvalidOperationException

Replicate(string?, int?)

REPLICATE (Transact-SQL)

Repeats a string value a specified number of times.

[Sql.Function("SqlServer", "REPLICATE", ServerSideOnly = true)]
public static string? Replicate(string? string_expression, int? integer_expression)

Parameters

string_expression string

Is an expression of a character string or binary data type.

integer_expression int?

Is an expression of any integer type, including bigint. If integer_expression is negative, NULL is returned.

Returns

string

Returns the same type as string_expression.

Exceptions

InvalidOperationException

Reverse(string?)

REVERSE (Transact-SQL)

Returns the reverse order of a string value.

[Sql.Function("SqlServer", "REVERSE", ServerSideOnly = true)]
public static string? Reverse(string? string_expression)

Parameters

string_expression string

string_expression is an expression of a string or binary data type. string_expression can be a constant, variable, or column of either character or binary data.

Returns

string

varchar or nvarchar

Exceptions

InvalidOperationException

Right(string?, int?)

RIGHT (Transact-SQL)

Returns the right part of a character string with the specified number of characters.

[Sql.Function("SqlServer", "RIGHT", ServerSideOnly = true)]
public static string? Right(string? character_expression, int? integer_expression)

Parameters

character_expression string

Is an expression of character or binary data. character_expression can be a constant, variable, or column. character_expression can be of any data type, except text or ntext, that can be implicitly converted to varchar or nvarchar. Otherwise, use the CAST function to explicitly convert character_expression.

integer_expression int?

Is a positive integer that specifies how many characters of the character_expression will be returned. If integer_expression is negative, an error is returned. If integer_expression is type bigint and contains a large value, character_expression must be of a large data type such as varchar(max). The integer_expression parameter counts a UTF-16 surrogate character as one character.

Returns

string

Returns varchar when character_expression is a non-Unicode character data type. Returns nvarchar when character_expression is a Unicode character data type.

Exceptions

InvalidOperationException

RightTrim(string?)

RTRIM (Transact-SQL)

Returns a character string after truncating all trailing spaces.

[Sql.Function("SqlServer", "RTRIM", ServerSideOnly = true)]
public static string? RightTrim(string? character_expression)

Parameters

character_expression string

Is an expression of character data. character_expression can be a constant, variable, or column of either character or binary data.

Returns

string

varchar or nvarchar

Exceptions

InvalidOperationException

Round<T>(T, int)

ROUND (Transact-SQL)

Returns a numeric value, rounded to the specified length or precision.

[Sql.Function("SqlServer", "ROUND", ServerSideOnly = true, IgnoreGenericParameters = true)]
public static T Round<T>(T numeric_expression, int length)

Parameters

numeric_expression T

An expression of the exact numeric or approximate numeric data type category, except for the bit data type.

length int

Is the precision to which numeric_expression is to be rounded. length must be an expression of type tinyint, smallint, or int. When length is a positive number, numeric_expression is rounded to the number of decimal positions specified by length. When length is a negative number, numeric_expression is rounded on the left side of the decimal point, as specified by length.

Returns

T

Return values have the same type as numeric_expression.

Type Parameters

T

Exceptions

InvalidOperationException

Round<T>(T, int, int)

ROUND (Transact-SQL)

Returns a numeric value, rounded to the specified length or precision.

[Sql.Function("SqlServer", "ROUND", ServerSideOnly = true, IgnoreGenericParameters = true)]
public static T Round<T>(T numeric_expression, int length, int function)

Parameters

numeric_expression T

An expression of the exact numeric or approximate numeric data type category, except for the bit data type.

length int

Is the precision to which numeric_expression is to be rounded. length must be an expression of type tinyint, smallint, or int. When length is a positive number, numeric_expression is rounded to the number of decimal positions specified by length. When length is a negative number, numeric_expression is rounded on the left side of the decimal point, as specified by length.

function int

Is the type of operation to perform. function must be tinyint, smallint, or int. When function is omitted or has a value of 0 (default), numeric_expression is rounded. When a value other than 0 is specified, numeric_expression is truncated

Returns

T

Return values have the same type as numeric_expression.

Type Parameters

T

Exceptions

InvalidOperationException

RowCountBig()

ROWCOUNT_BIG (Transact-SQL)

Returns the number of rows affected by the last statement executed. This function operates like @@ROWCOUNT, except the return type of ROWCOUNT_BIG is bigint.

[Sql.Function("SqlServer", "ROWCOUNT_BIG", ServerSideOnly = true)]
public static long RowCountBig()

Returns

long

bigint

Exceptions

InvalidOperationException

SchemaID()

SCHEMA_ID (Transact-SQL)

Returns the schema ID associated with a schema name.

[Sql.Function("SqlServer", "SCHEMA_ID", ServerSideOnly = true)]
public static int? SchemaID()

Returns

int?

int

Exceptions

InvalidOperationException

SchemaID(string)

SCHEMA_ID (Transact-SQL)

Returns the schema ID associated with a schema name.

[Sql.Function("SqlServer", "SCHEMA_ID", ServerSideOnly = true)]
public static int? SchemaID(string schema_name)

Parameters

schema_name string

Is the name of the schema. schema_name is a sysname. If schema_name is not specified, SCHEMA_ID will return the ID of the default schema of the caller.

Returns

int?

int

Exceptions

InvalidOperationException

SchemaName()

SCHEMA_NAME (Transact-SQL)

Returns the schema name associated with a schema ID.

[Sql.Function("SqlServer", "SCHEMA_NAME", ServerSideOnly = true)]
public static string? SchemaName()

Returns

string

sysname

Exceptions

InvalidOperationException

SchemaName(int?)

SCHEMA_NAME (Transact-SQL)

Returns the schema name associated with a schema ID.

[Sql.Function("SqlServer", "SCHEMA_NAME", ServerSideOnly = true)]
public static string? SchemaName(int? schema_id)

Parameters

schema_id int?

The ID of the schema. schema_id is an int. If schema_id is not defined, SCHEMA_NAME will return the name of the default schema of the caller.

Returns

string

sysname

Exceptions

InvalidOperationException

ScopeIdentity()

SCOPE_IDENTITY (Transact-SQL)

Returns the last identity value inserted into an identity column in the same scope. A scope is a module: a stored procedure, trigger, function, or batch. Therefore, if two statements are in the same stored procedure, function, or batch, they are in the same scope.

[Sql.Function("SqlServer", "SCOPE_IDENTITY", ServerSideOnly = true)]
public static decimal ScopeIdentity()

Returns

decimal

numeric(38,0)

Exceptions

InvalidOperationException

ServerProperty(ServerPropertyName)

SERVERPROPERTY (Transact-SQL)

Returns property information about the server instance.

[Sql.Extension("SqlServer", "SERVERPROPERTY", ServerSideOnly = true, BuilderType = typeof(SqlFn.PropertyBuilder<SqlFn.ServerPropertyName>))]
public static object? ServerProperty(SqlFn.ServerPropertyName property)

Parameters

property SqlFn.ServerPropertyName

Is an expression that contains the property information to be returned for the server.

Returns

object

sql_variant

Exceptions

InvalidOperationException

Sign<T>(T)

SIGN (Transact-SQL)

Returns the positive (+1), zero (0), or negative (-1) sign of the specified expression.

[Sql.Function("SqlServer", "SIGN", ServerSideOnly = true, IgnoreGenericParameters = true)]
public static T Sign<T>(T numeric_expression)

Parameters

numeric_expression T

An expression of the exact numeric or approximate numeric data type category, except for the bit data type.

Returns

T

Return values have the same type as numeric_expression.

Type Parameters

T

Exceptions

InvalidOperationException

Sin<T>(T, T)

SIN (Transact-SQL)

Returns the trigonometric sine of the specified angle, in radians, and in an approximate numeric, float, expression.

[Sql.Function("SqlServer", "SIN", ServerSideOnly = true, IgnoreGenericParameters = true)]
public static T Sin<T>(T float_expression, T y)

Parameters

float_expression T

Is an expression of type float or of a type that can be implicitly converted to float, in radians.

y T

Returns

T

float

Type Parameters

T

Exceptions

InvalidOperationException

SmallDateTimeFromParts(int?, int?, int?, int?, int?)

SMALLDATETIMEFROMPARTS (Transact-SQL)

Returns a smalldatetime value for the specified date and time.

[Sql.Function("SqlServer", "SMALLDATETIMEFROMPARTS", ServerSideOnly = true)]
public static DateTime? SmallDateTimeFromParts(int? year, int? month, int? day, int? hour, int? minute)

Parameters

year int?
month int?
day int?
hour int?
minute int?

Returns

DateTime?

datetime

Exceptions

InvalidOperationException

SoundEx(string?)

SOUNDEX (Transact-SQL)

Returns a four-character (SOUNDEX) code to evaluate the similarity of two strings.

[Sql.Function("SqlServer", "SOUNDEX", ServerSideOnly = true)]
public static string? SoundEx(string? character_expression)

Parameters

character_expression string

Is an alphanumeric expression of character data. character_expression can be a constant, variable, or column.

Returns

string

varchar

Exceptions

InvalidOperationException

Space(int?)

SPACE (Transact-SQL)

Returns a string of repeated spaces.

[Sql.Function("SqlServer", "SPACE", ServerSideOnly = true)]
public static string? Space(int? integer_expression)

Parameters

integer_expression int?

Is a positive integer that indicates the number of spaces. If integer_expression is negative, a null string is returned.

Returns

string

varchar

Exceptions

InvalidOperationException

Sqrt<T>(T)

SQRT (Transact-SQL)

Returns the square root of the specified float value.

[Sql.Function("SqlServer", "SQRT", ServerSideOnly = true, IgnoreGenericParameters = true)]
public static T Sqrt<T>(T float_expression)

Parameters

float_expression T

Is an expression of type float or of a type that can be implicitly converted to float.

Returns

T

float

Type Parameters

T

Exceptions

InvalidOperationException

Square<T>(T)

SQUARE (Transact-SQL)

Returns the square of the specified float value.

[Sql.Function("SqlServer", "SQUARE", ServerSideOnly = true, IgnoreGenericParameters = true)]
public static T Square<T>(T float_expression)

Parameters

float_expression T

Is an expression of type float or of a type that can be implicitly converted to float.

Returns

T

float

Type Parameters

T

Exceptions

InvalidOperationException

StatsDate(int?, int?)

STATS_DATE (Transact-SQL)

Returns the date of the most recent update for statistics on a table or indexed view.

[Sql.Function("SqlServer", "STATS_DATE", ServerSideOnly = true)]
public static DateTime? StatsDate(int? object_id, int? stats_id)

Parameters

object_id int?

ID of the table or indexed view with the statistics.

stats_id int?

ID of the statistics object.

Returns

DateTime?

Returns datetime on success. Returns NULL if a statistics blob was not created.

Exceptions

InvalidOperationException

Str<T>(T?)

STR (Transact-SQL)

Returns character data converted from numeric data. The character data is right-justified, with a specified length and decimal precision.

[Sql.Function("SqlServer", "STR", ServerSideOnly = true, IgnoreGenericParameters = true)]
public static string? Str<T>(T? float_expression)

Parameters

float_expression T

Is an expression of approximate numeric (float) data type with a decimal point.

Returns

string

varchar

Type Parameters

T

Exceptions

InvalidOperationException

Str<T>(T?, int)

STR (Transact-SQL)

Returns character data converted from numeric data. The character data is right-justified, with a specified length and decimal precision.

[Sql.Function("SqlServer", "STR", ServerSideOnly = true, IgnoreGenericParameters = true)]
public static string? Str<T>(T? float_expression, int length)

Parameters

float_expression T

Is an expression of approximate numeric (float) data type with a decimal point.

length int

Is the total length. This includes decimal point, sign, digits, and spaces. The default is 10.

Returns

string

varchar

Type Parameters

T

Exceptions

InvalidOperationException

Str<T>(T?, int, int)

STR (Transact-SQL)

Returns character data converted from numeric data. The character data is right-justified, with a specified length and decimal precision.

[Sql.Function("SqlServer", "STR", ServerSideOnly = true, IgnoreGenericParameters = true)]
public static string? Str<T>(T? float_expression, int length, int @decimal)

Parameters

float_expression T

Is an expression of approximate numeric (float) data type with a decimal point.

length int

Is the total length. This includes decimal point, sign, digits, and spaces. The default is 10.

decimal int

Is the number of places to the right of the decimal point. decimal must be less than or equal to 16. If decimal is more than 16 then the result is truncated to sixteen places to the right of the decimal point.

Returns

string

varchar

Type Parameters

T

Exceptions

InvalidOperationException

StringEscape(string?, string?)

STRING_ESCAPE (Transact-SQL)

Returns character data converted from numeric data. The character data is right-justified, with a specified length and decimal precision.

[Sql.Function("SqlServer", "STRING_ESCAPE", ServerSideOnly = true, IgnoreGenericParameters = true)]
public static string? StringEscape(string? text, string? type)

Parameters

text string

Is a nvarchar expression expression representing the object that should be escaped.

type string

Escaping rules that will be applied. Currently the value supported is 'json'.

Returns

string

varchar

Exceptions

InvalidOperationException

Stuff(string?, int?, int?, string?)

STUFF (Transact-SQL)

The STUFF function inserts a string into another string. It deletes a specified length of characters in the first string at the start position and then inserts the second string into the first string at the start position.

[Sql.Function("SqlServer", "STUFF", ServerSideOnly = true, IgnoreGenericParameters = true)]
public static string? Stuff(string? character_expression, int? start, int? length, string? replaceWith_expression)

Parameters

character_expression string

Is an expression of character data. character_expression can be a constant, variable, or column of either character or binary data.

start int?

Is an integer value that specifies the location to start deletion and insertion. If start is negative or zero, a null string is returned. If start is longer than the first character_expression, a null string is returned. start can be of type bigint.

length int?

Is an integer that specifies the number of characters to delete. If length is negative, a null string is returned. If length is longer than the first character_expression, deletion occurs up to the last character in the last character_expression. If length is zero, insertion occurs at start location and no characters are deleted. length can be of type bigint.

replaceWith_expression string

Is an expression of character data. character_expression can be a constant, variable, or column of either character or binary data. This expression replaces length characters of character_expression beginning at start. Providing NULL as the replaceWith_expression, removes characters without inserting anything.

Returns

string

Returns character data if character_expression is one of the supported character data types. Returns binary data if character_expression is one of the supported binary data types.

Exceptions

InvalidOperationException

Substring(string?, int?, int?)

SUBSTRING (Transact-SQL)

Returns part of a character, binary, text, or image expression in SQL Server.

[Sql.Function("SqlServer", "SUBSTRING", ServerSideOnly = true, IgnoreGenericParameters = true)]
public static string? Substring(string? expression, int? start, int? length)

Parameters

expression string

Is a character, binary, text, ntext, or image expression.

start int?

Is an integer or bigint expression that specifies where the returned characters start. (The numbering is 1 based, meaning that the first character in the expression is 1). If start is less than 1, the returned expression will begin at the first character that is specified in expression. In this case, the number of characters that are returned is the largest value of either the sum of start + length - 1 or 0. If start is greater than the number of characters in the value expression, a zero-length expression is returned.

length int?

Is a positive integer or bigint expression that specifies how many characters of the expression will be returned. If length is negative, an error is generated and the statement is terminated. If the sum of start and length is greater than the number of characters in expression, the whole value expression beginning at start is returned.

Returns

string

Returns character data if expression is one of the supported character data types. Returns binary data if expression is one of the supported binary data types.

Exceptions

InvalidOperationException

SwitchOffset(DateTimeOffset?, string)

SWITCHOFFSET (Transact-SQL)

Returns a datetimeoffset value that is changed from the stored time zone offset to a specified new time zone offset.

[Sql.Function("SqlServer", "SWITCHOFFSET", ServerSideOnly = true)]
public static DateTimeOffset? SwitchOffset(DateTimeOffset? datetimeoffset_expression, string timezoneoffset_expression)

Parameters

datetimeoffset_expression DateTimeOffset?
timezoneoffset_expression string

Returns

DateTimeOffset?

int

Exceptions

InvalidOperationException

SysDatetime()

SYSDATETIME (Transact-SQL)

Returns a datetime2(7) value that contains the date and time of the computer on which the instance of SQL Server is running.

[Sql.Function("SqlServer", "SYSDATETIME", ServerSideOnly = true)]
public static DateTime SysDatetime()

Returns

DateTime

datetime2(7)

Exceptions

InvalidOperationException

SysDatetimeOffset()

SYSDATETIMEOFFSET (Transact-SQL)

Returns a datetimeoffset(7) value that contains the date and time of the computer on which the instance of SQL Server is running. The time zone offset is included.

[Sql.Function("SqlServer", "SYSDATETIMEOFFSET", ServerSideOnly = true)]
public static DateTimeOffset SysDatetimeOffset()

Returns

DateTimeOffset

datetimeoffset(7)

Exceptions

InvalidOperationException

SysUtcDatetime()

SYSUTCDATETIME (Transact-SQL)

Returns a datetime2 value that contains the date and time of the computer on which the instance of SQL Server is running. The date and time is returned as UTC time (Coordinated Universal Time). The fractional second precision specification has a range from 1 to 7 digits. The default precision is 7 digits.

[Sql.Function("SqlServer", "SYSUTCDATETIME", ServerSideOnly = true)]
public static DateTime SysUtcDatetime()

Returns

DateTime

datetime2

Exceptions

InvalidOperationException

Tan<T>(T)

TAN (Transact-SQL)

Returns the tangent of the input expression.

[Sql.Function("SqlServer", "TAN", ServerSideOnly = true, IgnoreGenericParameters = true)]
public static T Tan<T>(T float_expression)

Parameters

float_expression T

Is an expression of type float or of a type that can be implicitly converted to float.

Returns

T

float

Type Parameters

T

Exceptions

InvalidOperationException

TimeFromParts(int?, int?, int?)

TIMEFROMPARTS (Transact-SQL)

This function returns a date value that maps to the specified year, month, and day values.

[Sql.Expression("SqlServer", "TIMEFROMPARTS({0}, {1}, {2}, 0, 0)", ServerSideOnly = true)]
public static TimeSpan? TimeFromParts(int? hour, int? minute, int? seconds)

Parameters

hour int?
minute int?
seconds int?

Returns

TimeSpan?

date

Exceptions

InvalidOperationException

TimeFromParts(int?, int?, int?, int?, int?)

TIMEFROMPARTS (Transact-SQL)

This function returns a date value that maps to the specified year, month, and day values.

[Sql.Function("SqlServer", "TIMEFROMPARTS", ServerSideOnly = true)]
public static TimeSpan? TimeFromParts(int? hour, int? minute, int? seconds, int? fractions, int? precision)

Parameters

hour int?
minute int?
seconds int?
fractions int?
precision int?

Returns

TimeSpan?

date

Exceptions

InvalidOperationException

ToDatetimeOffset(DateTimeOffset?, string)

TODATETIMEOFFSET (Transact-SQL)

Returns a datetimeoffset value that is translated from a datetime2 expression.

[Sql.Function("SqlServer", "TODATETIMEOFFSET", ServerSideOnly = true)]
public static DateTimeOffset? ToDatetimeOffset(DateTimeOffset? datetime_expression, string timezoneoffset_expression)

Parameters

datetime_expression DateTimeOffset?
timezoneoffset_expression string

Returns

DateTimeOffset?

int

Exceptions

InvalidOperationException

Translate(string?, string?, string?)

TRANSLATE (Transact-SQL)

Returns part of a character, binary, text, or image expression in SQL Server.

[Sql.Function("SqlServer", "TRANSLATE", ServerSideOnly = true, IgnoreGenericParameters = true)]
public static string? Translate(string? inputString, string? characters, string? translations)

Parameters

inputString string

inputString Is the string expression to be searched. inputString can be any character data type (nvarchar, varchar, nchar, char).

characters string
translations string

Is a string expression containing the replacement characters. translations must be the same data type and length as characters.

Returns

string

Returns a character expression of the same data type as inputString where characters from the second argument are replaced with the matching characters from third argument.

Exceptions

InvalidOperationException

Trim(string?)

TRIM (Transact-SQL)

Removes the space character char(32) or other specified characters from the start and end of a string.

[Sql.Function("SqlServer", "TRIM", ServerSideOnly = true)]
public static string? Trim(string? @string)

Parameters

string string

Is an expression of any character type (nvarchar, varchar, nchar, or char) where characters should be removed.

Returns

string

Returns a character expression with a type of string argument where the space character char(32) or other specified characters are removed from both sides. Returns NULL if input string is NULL.

Exceptions

InvalidOperationException

Trim(string, string?)

TRIM (Transact-SQL)

Removes the space character char(32) or other specified characters from the start and end of a string.

[Sql.Expression("SqlServer", "TRIM({0} FROM {1})", ServerSideOnly = true)]
public static string? Trim(string characters, string? @string)

Parameters

characters string

Is a literal, variable, or function call of any non-LOB character type (nvarchar, varchar, nchar, or char) containing characters that should be removed. nvarchar(max) and varchar(max) types aren't allowed.

string string

Is an expression of any character type (nvarchar, varchar, nchar, or char) where characters should be removed.

Returns

string

Returns a character expression with a type of string argument where the space character char(32) or other specified characters are removed from both sides. Returns NULL if input string is NULL.

Exceptions

InvalidOperationException

TryCast<T>(object?)

TRY_CAST (Transact-SQL)

These functions convert an expression of one data type to another.

[Sql.Expression("SqlServer", "TRY_CAST({0} as {1})", ServerSideOnly = true)]
public static T TryCast<T>(object? expression)

Parameters

expression object

Any valid expression.

Returns

T

Returns expression, translated to data_type.

Type Parameters

T

Exceptions

InvalidOperationException

TryCast<T>(object?, SqlType<T>)

TRY_CAST (Transact-SQL)

These functions convert an expression of one data type to another.

[Sql.Extension("SqlServer", "TRY_CAST({expression} as {data_type})", ServerSideOnly = true, BuilderType = typeof(SqlFn.DataTypeBuilder))]
public static T TryCast<T>(object? expression, SqlType<T> data_type)

Parameters

expression object

Any valid expression.

data_type SqlType<T>

The target data type. This includes xml, bigint, and sql_variant. Alias data types cannot be used.

Returns

T

Returns expression, translated to data_type.

Type Parameters

T

Exceptions

InvalidOperationException

TryCast<T>(object?, Func<SqlType<T>>)

TRY_CAST (Transact-SQL)

These functions convert an expression of one data type to another.

[Sql.Extension("SqlServer", "TRY_CAST({expression} as {data_type})", ServerSideOnly = true, BuilderType = typeof(SqlFn.DataTypeBuilder))]
public static T TryCast<T>(object? expression, Func<SqlType<T>> data_type)

Parameters

expression object

Any valid expression.

data_type Func<SqlType<T>>

The target data type. This includes xml, bigint, and sql_variant. Alias data types cannot be used.

Returns

T

Returns expression, translated to data_type.

Type Parameters

T

Exceptions

InvalidOperationException

TryConvert<T>(SqlType<T>, object?)

TRY_CONVERT (Transact-SQL)

These functions convert an expression of one data type to another.

[Sql.Extension("SqlServer", "TRY_CONVERT({data_type}, {expression})", ServerSideOnly = true, BuilderType = typeof(SqlFn.DataTypeBuilder))]
public static T TryConvert<T>(SqlType<T> data_type, object? expression)

Parameters

data_type SqlType<T>

The target data type. This includes xml, bigint, and sql_variant. Alias data types cannot be used.

expression object

Any valid expression.

Returns

T

Returns expression, translated to data_type.

Type Parameters

T

Exceptions

InvalidOperationException

TryConvert<T>(SqlType<T>, object?, int)

TRY_CONVERT (Transact-SQL)

These functions convert an expression of one data type to another.

[Sql.Extension("SqlServer", "TRY_CONVERT({data_type}, {expression}, {style})", ServerSideOnly = true, BuilderType = typeof(SqlFn.DataTypeBuilder))]
public static T TryConvert<T>(SqlType<T> data_type, object? expression, int style)

Parameters

data_type SqlType<T>

The target data type. This includes xml, bigint, and sql_variant. Alias data types cannot be used.

expression object

Any valid expression.

style int

Returns

T

Returns expression, translated to data_type.

Type Parameters

T

Exceptions

InvalidOperationException

TryConvert<T>(Func<SqlType<T>>, object?)

TRY_CONVERT (Transact-SQL)

These functions convert an expression of one data type to another.

[Sql.Extension("SqlServer", "TRY_CONVERT({data_type}, {expression})", ServerSideOnly = true, BuilderType = typeof(SqlFn.DataTypeBuilder))]
public static T TryConvert<T>(Func<SqlType<T>> data_type, object? expression)

Parameters

data_type Func<SqlType<T>>

The target data type. This includes xml, bigint, and sql_variant. Alias data types cannot be used.

expression object

Any valid expression.

Returns

T

Returns expression, translated to data_type.

Type Parameters

T

Exceptions

InvalidOperationException

TryConvert<T>(Func<SqlType<T>>, object?, int)

TRY_CONVERT (Transact-SQL)

These functions convert an expression of one data type to another.

[Sql.Extension("SqlServer", "TRY_CONVERT({data_type}, {expression}, {style})", ServerSideOnly = true, BuilderType = typeof(SqlFn.DataTypeBuilder))]
public static T TryConvert<T>(Func<SqlType<T>> data_type, object? expression, int style)

Parameters

data_type Func<SqlType<T>>

The target data type. This includes xml, bigint, and sql_variant. Alias data types cannot be used.

expression object

Any valid expression.

style int

Returns

T

Returns expression, translated to data_type.

Type Parameters

T

Exceptions

InvalidOperationException

TryConvert<T>(object?)

TRY_CONVERT (Transact-SQL)

These functions convert an expression of one data type to another.

[Sql.Expression("SqlServer", "TRY_CONVERT({1}, {0})", ServerSideOnly = true)]
public static T TryConvert<T>(object? expression)

Parameters

expression object

Any valid expression.

Returns

T

Returns expression, translated to data_type.

Type Parameters

T

Exceptions

InvalidOperationException

TryConvert<T>(object?, int)

TRY_CONVERT (Transact-SQL)

These functions convert an expression of one data type to another.

[Sql.Expression("SqlServer", "TRY_CONVERT({2}, {0}, {1})", ServerSideOnly = true)]
public static T TryConvert<T>(object? expression, int style)

Parameters

expression object

Any valid expression.

style int

Returns

T

Returns expression, translated to data_type.

Type Parameters

T

Exceptions

InvalidOperationException

TryParse<T>(string)

TRY_PARSE (Transact-SQL)

Returns the result of an expression, translated to the requested data type in SQL Server.

[Sql.Expression("SqlServer", "TRY_PARSE({0} as {1})", ServerSideOnly = true)]
public static T TryParse<T>(string string_value)

Parameters

string_value string

nvarchar(4000) value representing the formatted value to parse into the specified data type.

Returns

T

Returns the result of the expression, translated to the requested data type.

Type Parameters

T

Exceptions

InvalidOperationException

TryParse<T>(string, SqlType<T>)

TRY_PARSE (Transact-SQL)

Returns the result of an expression, translated to the requested data type in SQL Server.

[Sql.Extension("SqlServer", "TRY_PARSE({string_value} as {data_type})", ServerSideOnly = true, BuilderType = typeof(SqlFn.DataTypeBuilder))]
public static T TryParse<T>(string string_value, SqlType<T> data_type)

Parameters

string_value string

nvarchar(4000) value representing the formatted value to parse into the specified data type.

data_type SqlType<T>

Literal value representing the data type requested for the result.

Returns

T

Returns the result of the expression, translated to the requested data type.

Type Parameters

T

Exceptions

InvalidOperationException

TryParse<T>(string, SqlType<T>, string)

TRY_PARSE (Transact-SQL)

Returns the result of an expression, translated to the requested data type in SQL Server.

[Sql.Extension("SqlServer", "TRY_PARSE({string_value} as {data_type} USING {culture})", ServerSideOnly = true, BuilderType = typeof(SqlFn.DataTypeBuilder))]
public static T TryParse<T>(string string_value, SqlType<T> data_type, string culture)

Parameters

string_value string

nvarchar(4000) value representing the formatted value to parse into the specified data type.

data_type SqlType<T>

Literal value representing the data type requested for the result.

culture string

Optional string that identifies the culture in which string_value is formatted.

Returns

T

Returns the result of the expression, translated to the requested data type.

Type Parameters

T

Exceptions

InvalidOperationException

TryParse<T>(string, Func<SqlType<T>>)

TRY_PARSE (Transact-SQL)

Returns the result of an expression, translated to the requested data type in SQL Server.

[Sql.Extension("SqlServer", "TRY_PARSE({string_value} as {data_type})", ServerSideOnly = true, BuilderType = typeof(SqlFn.DataTypeBuilder))]
public static T TryParse<T>(string string_value, Func<SqlType<T>> data_type)

Parameters

string_value string

nvarchar(4000) value representing the formatted value to parse into the specified data type.

data_type Func<SqlType<T>>

Literal value representing the data type requested for the result.

Returns

T

Returns the result of the expression, translated to the requested data type.

Type Parameters

T

Exceptions

InvalidOperationException

TryParse<T>(string, Func<SqlType<T>>, string)

TRY_PARSE (Transact-SQL)

Returns the result of an expression, translated to the requested data type in SQL Server.

[Sql.Extension("SqlServer", "TRY_PARSE({string_value} as {data_type} USING {culture})", ServerSideOnly = true, BuilderType = typeof(SqlFn.DataTypeBuilder))]
public static T TryParse<T>(string string_value, Func<SqlType<T>> data_type, string culture)

Parameters

string_value string

nvarchar(4000) value representing the formatted value to parse into the specified data type.

data_type Func<SqlType<T>>

Literal value representing the data type requested for the result.

culture string

Optional string that identifies the culture in which string_value is formatted.

Returns

T

Returns the result of the expression, translated to the requested data type.

Type Parameters

T

Exceptions

InvalidOperationException

TryParse<T>(string, string)

TRY_PARSE (Transact-SQL)

Returns the result of an expression, translated to the requested data type in SQL Server.

[Sql.Expression("SqlServer", "TRY_PARSE({0} as {2} USING {1})", ServerSideOnly = true)]
public static T TryParse<T>(string string_value, string culture)

Parameters

string_value string

nvarchar(4000) value representing the formatted value to parse into the specified data type.

culture string

Optional string that identifies the culture in which string_value is formatted.

Returns

T

Returns the result of the expression, translated to the requested data type.

Type Parameters

T

Exceptions

InvalidOperationException

TypeID(string)

TYPE_ID (Transact-SQL)

Returns the ID for a specified data type name.

[Sql.Function("SqlServer", "TYPE_ID", ServerSideOnly = true)]
public static int? TypeID(string type_name)

Parameters

type_name string

Is the name of the data type. type_name is of type nvarchar. type_name can be a system or user-defined data type.

Returns

int?

int

Exceptions

InvalidOperationException

TypeName(int?)

TYPE_NAME (Transact-SQL)

Returns the unqualified type name of a specified type ID.

[Sql.Function("SqlServer", "TYPE_NAME", ServerSideOnly = true)]
public static string? TypeName(int? type_id)

Parameters

type_id int?

Is the ID of the type that will be used. type_id is an int, and it can refer to a type in any schema that the caller has permission to access.

Returns

string

sysname

Exceptions

InvalidOperationException

TypeProperty(string?, TypePropertyName)

TYPEPROPERTY (Transact-SQL)

Returns information about a data type.

[Sql.Extension("SqlServer", "TYPEPROPERTY", ServerSideOnly = true, BuilderType = typeof(SqlFn.PropertyBuilder<SqlFn.TypePropertyName>))]
public static int? TypeProperty(string? type, SqlFn.TypePropertyName property)

Parameters

type string

Is the name of the data type.

property SqlFn.TypePropertyName

Is the type of information to be returned for the data type.

Returns

int?

int

Exceptions

InvalidOperationException

Unicode(string)

UNICODE (Transact-SQL)

Removes the space character char(32) or other specified characters from the start and end of a string.

[Sql.Function("SqlServer", "UNICODE", ServerSideOnly = true)]
public static int? Unicode(string ncharacter_expression)

Parameters

ncharacter_expression string

Is an nchar or nvarchar expression.

Returns

int?

int

Exceptions

InvalidOperationException

Upper(string?)

UPPER (Transact-SQL)

Returns a character expression after converting uppercase character data to lowercase.

[Sql.Function("SqlServer", "UPPER", ServerSideOnly = true)]
public static string? Upper(string? character_expression)

Parameters

character_expression string

Is the string expression of character or binary data. character_expression can be a constant, variable, or column. character_expression must be of a data type that is implicitly convertible to varchar.

Returns

string

varchar or nvarchar

Exceptions

InvalidOperationException

XactState()

XACT_STATE (Transact-SQL)

Is a scalar function that reports the user transaction state of a current running request. XACT_STATE indicates whether the request has an active user transaction, and whether the transaction is capable of being committed.

[Sql.Function("SqlServer", "XACT_STATE", ServerSideOnly = true)]
public static short XactState()

Returns

short

smallint

Exceptions

InvalidOperationException

Year(DateTimeOffset?)

YEAR (Transact-SQL)

This function returns an integer that represents the day (day of the month) of the specified date.

[Sql.Function("SqlServer", "YEAR", ServerSideOnly = true)]
public static int? Year(DateTimeOffset? date)

Parameters

date DateTimeOffset?

Returns

int?

int

Exceptions

InvalidOperationException

Year(DateTime?)

YEAR (Transact-SQL)

This function returns an integer that represents the day (day of the month) of the specified date.

[Sql.Function("SqlServer", "YEAR", ServerSideOnly = true)]
public static int? Year(DateTime? date)

Parameters

date DateTime?

Returns

int?

int

Exceptions

InvalidOperationException

Year(string?)

YEAR (Transact-SQL)

Returns an integer that represents the year of the specified date.

[Sql.Function("SqlServer", "YEAR", ServerSideOnly = true)]
public static int? Year(string? date)

Parameters

date string

Returns

int?

int

Exceptions

InvalidOperationException