Dynamic Views


Compared with stored procedures, views have one serious limitation—they do not support parameters. Fortunately, you can use a table-valued user-defined function as a dynamic view, which does support parameters (you can also call them parameterized views):

      Create Function dbo.fnlnventoryByLocationId(             @LocationId int)      Returns Table      AS      Return (SELECT *              FROM dbo.vInventory              WHERE LocationId = OLocationId} 

They can be referenced in the From clause of a Select statement, which makes them work like a view:

      select *      from dbo.fnInventoryByLocationId (2) 

We will discuss table-valued user-defined functions in Chapter 10.




Microsoft SQL Server 2005 Stored Procedure Programming in T-SQL &  .NET
Microsoft SQL Server 2005 Stored Procedure Programming in T-SQL & .NET
ISBN: 0072262281
EAN: 2147483647
Year: 2006
Pages: 165

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net