Example
Return the name of the current user in the SQL Server database:
SELECT CURRENT_USER;
Definition and Usage
The CURRENT_USER function returns the name of the current user in the SQL Server database.
Syntax
CURRENT_USER
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))
Return the year part of a date:
SELECT YEAR('2017/08/25') AS Year;
The YEAR() function returns the year part for a specified date.
YEAR(date)
Return the date and time of the SQL Server:
SELECT SYSDATETIME() AS SysDateTime;
The SYSDATETIME() function returns the date and time of the computer where the SQL Server is running.
SYSDATETIME()
Return the month part of a date:
SELECT MONTH('2017/08/25') AS Month;
The MONTH() function returns the month part for a specified date (a number from 1 to 12).
MONTH(date)
Check if the expression is a valid date:
SELECT ISDATE('2017-08-25');
The ISDATE() function checks an expression and returns 1 if it is a valid date, otherwise 0.
ISDATE(expression)
Return the current UTC date and time:
SELECT GETUTCDATE();
The GETUTCDATE() function returns the current database system UTC date and time, in a ‘YYYY-MM-DD hh:mm:ss.mmm’ format.
GETUTCDATE()
Return the current database system date and time:
SELECT GETDATE();
The GETDATE() function returns the current database system date and time, in a ‘YYYY-MM-DD hh:mm:ss.mmm’ format.
Tip: Also look at the CURRENT_TIMESTAMP function.
GETDATE()