Building Expressions
You can construct SQL expressions from a nearly limitless list of constants, variables, operators, and functions, as detailed in Table 8.5.
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() |
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.