Code (UDF-Tutorial)
Code (UDF-Tutorial)
------------------------------------------------------
-- @ Scalar function.
------------------------------------------------------
-- http://www.sqlservercurry.com/2014/03/user-defined-functions-in-sql-server_20.html
USE northwind
GO
-- Scalar Function
---------------------------------------------------------------
-- Feach the total number of orders placed by a given customer.
drop function dbo.fn_name
create function fn_name()
returns Int
Begin
return ( select 2)
End
-- Test Function
Select dbo.FetchEmployeeProcessedOrdersYearWise(1, 1996) as 'Year 1996'
union
Select dbo.FetchEmployeeProcessedOrdersYearWise(1, 1997) as 'Year 1997'
union
Select dbo.FetchEmployeeProcessedOrdersYearWise(1, 1998) as 'Year 1998';
---------------------------------------------------------------------------
-- InLine Table valued functions
---------------------------------------------------------------------------
-- The following uses the Customer table in the Northwind database
-- to show
-- how an inline table-valued function is implemented.
USE Northwind
go;
drop function fx_Customers_ByCity
-- *************************************************