Microsoft® SQL Server® 2012 Bible

(Ben Green) #1

197


Chapter 8: Data Types, Expressions, and Scalar Functions


8


Using the offset values, you can represent time zone offsets. However, you must provide
both offsets if you plan to use these values. If one is supplied without the other, the func-
tion raises an error.

The SmallDateTimeFromParts(year, month, day, hour, minute) function returns
a DateTime value based on the given values. The following example returns a datetime
value:

SELECT SmallDateTimeFromParts(1972, 5, 26, 5, 12) As Results

The TimeFromParts(hour, minute, seconds, fractions, precision) function returns
a Time value based on the given values. The following example returns a datetime value:

SELECT TimeFromParts(5, 12, 47, 3, 7) As Results

The precision and fractions’ values follow the same rules as the DateTime2FromParts
function.

If any arguments for any of the aforementioned functions are invalid an error will be
raised. Also, if a null value is supplied for any of the values, a null value is returned.

String Functions ................................................................................................


Like most modern programming languages, T-SQL includes many string-manipulation
functions:

■ (^) SUBSTRING(string, starting position, length)
■ STUFF(string, insertion position, delete count, string inserted)
■ (^) CHARINDEX(search string, string, starting position)
■ PATINDEX(pattern, string)
■ (^) RIGHT(string, count) and Left(string, count)
■ LEN(string)
■ (^) RTRIM(string) and LTrim(string)
■ UPPER(string) and Lower(string):
■ (^) REPLACE(string, string):
■ dbo.pTitleCase (source, search, replace)
SUBSTRING (string, starting position, length)
Substring function returns a portion of a string. The fi rst parameter is the string; the sec-
ond parameter is the beginning position of the substring to be extracted; and the third
parameter is the length of the string extracted:
c08.indd 197c08.indd 197 7/30/2012 4:21:15 PM7/30/2012 4:21:15 PM
http://www.it-ebooks.info

Free download pdf