Parameterized Views

On SQL Server, an inline table-valued function is as close as you can get to a parameterized view. Like a view, an inline function doesn't have a body. It consists of a SELECT statement only. Of course, the SELECT may include unions and complex joins, but regardless it's still just a single SELECT. What an inline table gives you is a way to pass parameters into the SELECT. That is, instead of having to construct a WHERE clause every time you want to filter the view, with an inline function, you just pass in parameters. This is syntactically more concise and less error prone, and it gives you greater control over the query plan that will be produced. Oftentimes, when applying complex filter criteria in a SELECT that accesses ...

Get Guru's Guide to SQL Server™ Stored Procedures, XML, and HTML, The 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.