O'Reilly logo

Microsoft SQL Server 2012 Bible by Aaron Nelson, Jose Chinchilla, Patrick LeBlanc, Jorge Segarra, Adam Jorgensen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required