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.

Chapter 13: User-Defined Functions<br />

Summary<br />

What we added in this chapter was, in many ways, not new at all. Indeed, much of what goes into userdefined<br />

functions is the same set of statements, variables, and general coding practices that we have<br />

already seen in scripting and stored procedures. However, UDFs still provide us a wonderful new area<br />

of functionality that was not previously available in <strong>SQL</strong> <strong>Server</strong>. We can now encapsulate a wider range<br />

of code, and even use this encapsulated functionality inline with our queries. What’s more, we can now<br />

also provide parameterized views and dynamically created tables.<br />

User-defined functions are, in many ways, the most exciting of all the new functionality added to <strong>SQL</strong><br />

<strong>Server</strong>. In pondering their uses, I have already come to realize that I’m only scratching the surface of<br />

their potential. Over the life of this next release, I suspect that developers will implement UDFs in ways I<br />

have yet to dream of — let’s hope you’ll be one of those developers!<br />

Exercise<br />

1. Reimplement the spTriangular function from Chapter 12 as a function instead of a stored<br />

procedure.<br />

426

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

Saved successfully!

Ooh no, something went wrong!