SQL Server view or table-valued function?

Striker picture Striker · May 13, 2011 · Viewed 24k times · Source

Anyone have a good decisioning tree for deciding when to use a view and when to use a table-valued function in SQL Server?

Answer

Cade Roux picture Cade Roux · May 13, 2011

Although any view can almost trivially be converted to an inline table-valued function, the converse is not true.

If the construct needs to be parametrized, then use an inline table-valued function. Inline table-value functions are basically parametrized views in terms of the optimizer being able to combine them with views and push things around. Multi-statement table-valued functions are not at all like inline table-valued functions.

If you cannot do it with an inline table-valued function, use a multi-statement table-valued function.