Question

The following excerpt is extract from this page.

CURRENT_USER (Transact-SQL)

Returns the name of the current user. This function is equivalent to USER_NAME().

When I execute the two function with the following TSQL scripts (the questionable ones were commented), I'm confused about the invocation syntax. I want to know when to use the parenthesis and when not. Thanks!

SELECT CURRENT_USER
-- SELECT CURRENT_USER() -- Error!
SELECT USER_NAME()
-- SELECT USER_NAME -- Error!
Was it helpful?

Solution

The ones without parentheses such as CURRENT_USER and CURRENT_TIMESTAMP are there for ANSI 92 compliance. There are only five such Niladic Functions and the list hasn't changed since SQL Server 6.0.

  1. CURRENT_USER
  2. CURRENT_TIMESTAMP
  3. SESSION_USER
  4. SYSTEM_USER
  5. USER

Most other SQL Server system functions require parentheses.

The exception to this are those functions that used to be known as global variables that are prefixed with @@ such as @@SPID.

This last group of functions can be passed directly in a parameter list to a stored procedure. Neither of the other two variants can.

Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top