17.06.2013 Views

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Yields:<br />

YEAR<br />

SELECT TODATETIMEOFFSET(@OurDateTimeTest, ‘-07:00’);<br />

----------------------------------<br />

1/1/<strong>2008</strong> 12:54:00 PM -07:00<br />

(local)(sa): (1 row(s) affected)<br />

The YEAR function returns an integer that represents the year part of the specified date. The syntax is as<br />

follows:<br />

YEAR()<br />

The YEAR function is equivalent to DATEPART(yy, ).<br />

Hierarchy Functions<br />

As mentioned before, the new implementation of hierarchyIDs is somewhat beyond the scope of this<br />

title. For detailed explanations on the use of the following functions please refer to the professional version<br />

of this book. For now we will just list, and briefly describe, the functions provided by <strong>SQL</strong> <strong>Server</strong><br />

<strong>2008</strong> to assist in working with the hierarchyIDs and the trees associated with them.<br />

GetAncestor<br />

The GetAncestor function returns the hierarchyID of n th ancestor of the item in question. The syntax is<br />

as follows:<br />

GetAncestor()<br />

The parameter passed in determines how many levels up the hierarchy chain you wish to retrieve descendants<br />

from. For example, 1 would return children of the item in question, 2 would return the grandchildren,<br />

and 0 would return the hierarchyID of the item in question itself.<br />

GetDescendant<br />

Returns a child node of the parent.<br />

GetLevel<br />

Returns an integer that represents the depth of the node in the tree.<br />

Apendix A: System Functions<br />

609

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!