Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

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!
share|improve this question
add comment

1 Answer 1

up vote 5 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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