How to calculate percentage using function in ms sql server
Microsoft Net Framework

How to calculate percentage using function in ms sql server


SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:        <Author,,Name>
-- Create date: <Create Date, ,>
-- Description:    <Description, ,>
-- =============================================
CREATE FUNCTION [dbo].[CalculatePercentage] 
(
    -- Add the parameters for the function here
    
     @Obtain AS INTEGER = 0,
      
      @All  AS INTEGER = 0
)
RETURNS int
AS
BEGIN
    -- Declare the return variable here    
    
    DECLARE  @percentage as decimal(18,2)=0;
    set @percentage=cast(@Obtain/(convert(decimal(18,2),@All)) * 100  as int )     
    return  @percentage 

END


Caculate percentage
show percentage in ms sql server.

Share This with your friend by choosing any social account


Upcoming Articles
You may also read following recent Post
Copyright Future Minutes © 2015- 2024 All Rights Reserved.   Terms of Service  |   Privacy Policy |  Contact US|  Pages|  Whats new?
Update on: Dec 20 2023 05:10 PM