how to create scalar valued function in sql server.

Total Post:341

 1032  View(s)
Rate this:
Can anyone please help me how to solve this problem.
  1. Post:279

    Re: how to create scalar 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 scalar function, which returns the total of price filtered by a given  category . Write the following code in your query pad –

     Create function fnGetTotatPrice


     @categoryId int


    returns decimal(10,2)


    Begin return ( select sum(price) from ProductMasters where CategoryId=@categoryId)


    --The above function returns an integer value. To test this function, we will write some code as shown below –

    select dbo.fnGetTotatPrice(2) as price

      Modified On Apr-10-2018 04:48:18 AM



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