1

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!

1 Answer 1

5

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.