HOW TO CREATE TABLE VALUED FUNCTION IN SQL SERVER .

Ankit Singh

Total Post:341

Points:2389
Posted by  Ankit Singh
 652  View(s)
Ratings:
Rate this:
Can anyone please help me how to solve this problem.
  1. aditya kumar Patel

    Post:254

    Points:1810
    Re: how to create table valued function in sql server .

    
    
    

    --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) 

    Result

     

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!