Home > DeveloperSection > Forums > how to create table valued function in sql server .
Ankit Singh

Total Post:341

Posted on    October-16-2015 11:00 PM

 MSSQL Server SQL Server  SQL  SQL Server 2008  SQL Server 2012 

 1 Reply(s)
 593  View(s)
Rate this:
Can anyone please help me how to solve this problem.

aditya kumar Patel

Total Post:254

Posted on    October-16-2015 11:07 PM

--let’s start querying create a table.

 CREATE TABLE ProductMasters(

       ProductId int IDENTITY(1,1) primary key,

       ProductName nvarchar(max) ,

       Price decimal(18, 2)  ,

       CategoryId int  


 --We will now create a table valued function, which returns the total of price filtered by a given category . Write the following code in your query pad –

 Create function fnGetProductMasters


 @categoryId int


returns table

return ( select * from ProductMasters where CategoryId=@categoryId)

--The above function returns an table. To test this function, we will write some code as shown below – select * from dbo.fnGetProductMasters(2) 



Don't want to miss updates? Please click the below button!

Follow MindStick