Cari Blog Ini

21 Maret 2012

Syntax : CREATE FUNCTION - Return Table - With Parameters

Applies To:
Microsoft SQL Server 2008


1. CREATE FUNCTION

-----start-----
USE AdventureWorks
go

CREATE FUNCTION A_Show_Product () 
RETURNS TABLE         
AS RETURN
(            
    SELECT * FROM Production.Product WHERE PRODUCTID='1' 
)   
-----end-----

---SELECT * FROM A_Show_Product()



2. CREATE FUNCTION Using Parameters

-----start-----
USE AdventureWorks
go

CREATE FUNCTION A_Show_Product_WithParams (@ProductID_First AS INT,@ProductID_Last AS INT  ) 
RETURNS TABLE         
AS RETURN
(            
    SELECT * FROM Production.Product WHERE PRODUCTID BETWEEN @ProductID_First AND @ProductID_Last
)
-----end-----

--SELECT * FROM A_Show_Product_WithParams( '1','4' )  




About :

01 - Create Function with Return Table in SQL Server
02 - Syntax : CREATE FUNCTION - Return Table - With Parameters
03 - Example of Create Function in SQL with Returns Value
04 - Example of Create Function (No Parameter) in SQL with Returns Value
05 - How to Use Function Intersect
06 - How to Use Function Except