Appendix B

T-SQL System Variables and Functions

The terms “variable” and “function” are often used interchangeably. SQL Server Books Online documents some variables as though they were functions. However, it is important to note that variables are used in expressions to obtain a value, whereas functions process specific business logic and may return a value. Many functions accept input arguments.

This appendix applies to SQL Server 2008, 2008 R2, and 2012. It is a reference of common T-SQL objects provided as a convenient guide to many functions and variables that may be useful in report queries. It is by no means meant to be a comprehensive reference. For complete details and examples of usage, consult Books Online.

System Global Variables

The system-supplied global variables are organized into the following categories:

  • Configuration
  • Cursor
  • System
  • System statistics

Configuration

Variable Return Type Description
@@DATEFIRST tinyint The system setting for the first day of the week:  1 = Monday  2 = Tuesday  3 = Wednesday  4 = Thursday  5 = Friday  6 = Saturday  7 = Sunday  The U.S. default is 7.
@@DBTS varbinary The last assigned unique TimeStamp value.
@@LANGID smallint The current language ID for the server:  0 = U.S. English  1 = German  2 = French

and so on.

@@LANGUAGE nvarchar The current language string for the server. Returns the language name in the native language form (us_english, Deutsch, Français, Dansk, Español, Italiano, and so on).
@@LOCK_TIMEOUT int

Get Professional Microsoft SQL Server 2012 Reporting Services now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.