177
Chapter 8: Data Types, Expressions, and Scalar Functions
8
VarBinary Variable-length binary data up to 8,000
bytes
Bytes used
Image Variable-length binary data up to
2,147,483,647 bytes: Warning: Deprecated
Bytes used
Sql_variant Can store any data type up to
2,147,483,647 bytes
Depends on data type
and length
Building Expressions ..........................................................................................
You can construct SQL expressions from a nearly limitless list of constants, variables, oper-
ators, 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-defi ned variables @MyVariable
System functions @@Error
Scalar functions GetDate(), Radians()
User-defi ned functions dbo.MyUDF()
c08.indd 177c08.indd 177 7/30/2012 4:21:12 PM7/30/2012 4:21:12 PM
http://www.it-ebooks.info