1: | User-defined functions can return scalar values as well as tables and can be used as part of the SELECT statement or in the FROM clause of a query. True or False? |
A1: | True |
2: | What are the three different types of user-defined functions? |
A2: | The three types of UDFs are
|
3: | Can I use a user-defined function instead of a view? |
A3: | Yes! In fact, by using a UDF instead of a view, performance will actually increase because the database does not have to maintain the view. |
1: | Using the Northwind database, create a function that accepts a ZIP Code and returns a table of customer names and addresses. |
A1: | This exercise needs only an inline table function as shown here:
CREATE FUNCTION Address_List (@zip nvarchar(10)) RETURNS Table AS Return (Select CompanyName, ContactName, Address, City, Region, PostalCode, Country From Customers Where PostalCode = @zip) |