Example
Return the session settings for a specified option:
SELECT SESSIONPROPERTY('ANSI_NULLS');
Definition and Usage
The SESSIONPROPERTY() function returns the session settings for a specified option.
Syntax
SESSIONPROPERTY(option)
Return the session settings for a specified option:
SELECT SESSIONPROPERTY('ANSI_NULLS');
The SESSIONPROPERTY() function returns the session settings for a specified option.
SESSIONPROPERTY(option)
Return the user name of the current user:
SELECT SESSION_USER;
The SESSION_USER function returns the name of the current user in the SQL Server database.
SESSION_USER
Compare two expressions:
SELECT NULLIF(25, 25);
The NULLIF() function returns NULL if two expressions are equal, otherwise it returns the first expression.
NULLIF(expr1, expr2)
Tests whether the expression is numeric:
SELECT ISNUMERIC(4567);
The ISNUMERIC() function tests whether an expression is numeric.
This function returns 1 if the expression is numeric, otherwise it returns 0.
ISNUMERIC(expression)
Return the specified value IF the expression is NULL, otherwise return the expression:
SELECT ISNULL(NULL, 'iampsp.com');
The ISNULL() function returns a specified value if the expression is NULL.
If the expression is NOT NULL, this function returns the expression.
ISNULL(expression, value)
Return “YES” if the condition is TRUE, or “NO” if the condition is FALSE:
SELECT IIF(500<1000, 'YES', 'NO');
The IIF() function returns a value if a condition is TRUE, or another value if a condition is FALSE.
IIF(condition, value_if_true, value_if_false)
Return the name of the current user in the SQL Server database:
SELECT CURRENT_USER;
The CURRENT_USER function returns the name of the current user in the SQL Server database.
CURRENT_USER
Convert an expression to int:
SELECT CONVERT(int, 25.65);
The CONVERT() function converts a value (of any type) into a specified datatype.
Tip: Also look at the CAST() function.
CONVERT(data_type(length), expression, style)
Return the first non-null value in a list:
SELECT COALESCE(NULL, NULL, NULL, 'iampsp.com', NULL, 'Example.com');
The COALESCE() function returns the first non-null value in a list.
COALESCE(val1, val2, ...., val_n)
Convert a value to an int datatype:
SELECT CAST(25.65 AS int);
The CAST() function converts a value (of any type) into a specified datatype.
Tip: Also look at the CONVERT() function.
CAST(expression AS datatype(length))