Search
 
SCRIPT & CODE EXAMPLE
 

SQL

sql calculate percentage

(round((CAST(numerator AS real) / denominator)*100,2)) as "percent"
Comment

sql percentage

SELECT CONCAT(ROUND(smallerNum*100/biggerNum, 2), '%') FROM table
Comment

calculate percentage in sql

SELECT SUM(MARKS)*100/COUNT(MARKS) FROM STUDENT_MARKS
Comment

sql server function to calculate a percentage

-- =============================================
-- Author:		Simphiwe Mabaso
-- Create date: 05 July 2022
-- Description:	When called this function returns a percentage
-- =============================================
ALTER   FUNCTION [dbo].[CalculatePercentage]
(
	@Value DECIMAL(18, 2),
	@Total DECIMAL(18, 2)
)
RETURNS INT
AS
BEGIN
	-- Declare the return variable here
	DECLARE @Percentage AS DECIMAL(18, 2);

	-- Add the T-SQL statements to compute the return value here
	SET @Percentage = @Value / @Total * 100;

	-- Return the result of the function
	RETURN @Percentage;
END

------------------------------------------------------
--Testing the function
DECLARE @Percent DECIMAL(18, 7),
		@PercentageInString NVARCHAR(50);

SET @Percent = dbo.CalculatePercentage(92, 45);

SET @PercentageInString = CONVERT(NVARCHAR(50), @Percent) + '%';

SELECT @PercentageInString  [Percentage];
Comment

PREVIOUS NEXT
Code Example
Sql :: mysql check if not null 
Sql :: postgresql search object in array 
Sql :: sql server set variable if exists 
Sql :: sql where keyword 
Sql :: change postgress password 
Sql :: add computed column to table sql server 
Sql :: how to fetch first 5 characters in sql 
Sql :: find duplicates mysql 
Sql :: python sqlalchemy connection show server 
Sql :: oracle drop index if exists 
Sql :: get value from a table an insert it with other values in another table sql 
Sql :: sql trim all spaces 
Sql :: drop table with constraints 
Sql :: mysql database manager 
Sql :: SQL Server - Count number of times a specific character appears in a string 
Sql :: sqlite woth cmake 
Sql :: change database name psql 8 
Sql :: mysql add column after another 
Sql :: sql upsert 
Sql :: mysql where value is null 
Sql :: run sql command line download for windows 10 
Sql :: current date sql 
Sql :: syntaxerror unexpected identifier mysql 
Sql :: java string to sql timestamp 
Sql :: sqlite indexes 
Sql :: sql create view 
Sql :: mysql current time 
Sql :: phone no data type in sql server 
Sql :: restroe pg_dump example 
Sql :: oracle number to percentage 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =