Building Expressions

You can construct SQL expressions from a nearly limitless list of constants, variables, operators, and functions, as detailed in Table 8.5.

Table 8.5 Building Expressions

Expression Components Examples
Numeric constants 1, 2, 3, -17, -100
String literals LastName', ‘Employee: ‘, ‘Lifes Great!'
Dates 1/30/1980', ‘January 30, 1980', ‘19800130'
Mathematical operators (in order of precedence) *, /, % (remainder), +, -
String operator (concatenation) +
Bitwise operators (in order of precedence) not, and &, or |, exclusive or
Columns LastName, PrimaryKeyID
Case expressions CASE Column1 WHEN 1 THEN ‘on' ELSE ‘off' END AS Status
Subqueries (Select 3)
User-defined variables @MyVariable
System functions @@Error
Scalar functions GetDate(), Radians()
User-defined functions dbo.MyUDF()
Note
The syntax of SQL keywords is not case-sensitive. The convention is to use keywords in all uppercase, all lowercase, camel case, etc. Regardless of the method you choose, that is the method that should be adopted throughout the entire database. This convention is not required, but it does improve the readability of the query.
Depending on the collation setting of the server or database, database, table, and column names, and even the data itself, might be case-sensitive.

referenceaero One thing that should be noted is the use of @, which is part of the variable declaration. ...

Get Microsoft SQL Server 2012 Bible 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.