Scalar functions return a single value. They are commonly used in expressions within the SELECT, WHERE, ORDER BY, GROUP, and HAVING clauses, or T-SQL code. SQL Server includes dozens of functions. This section describes some useful functions.
User Information Functions
In a client/server environment, it's good to know who the client is. Toward that end, the following four functions are useful, especially for gathering audit information:
- USER_NAME(): Returns the name of the current user as he or she is known to the database. When a user is granted access to a database, a username that is different from the server login name may be assigned. The results are affected by an EXECUTE AS command, in which case the username shown is that of the impersonated user.
- SUSER_SNAME(): Returns the login name by which the user was authenticated ...