How to create a Function in SQL Server

1
2
3
4
5
create function dbo.v_ts_employees
(@state varchar(2)) returns table
as
return
(Select * from employees where homestate = @State)

A function view is kind of cool because you can treat it just like a view.

For example

1
Select * from v_ts_employees('CA')