Quantcast
Channel: SQL Server Database Engine forum
Viewing all articles
Browse latest Browse all 12844

formula for calculating aggregate percentage and percenatge of gender

$
0
0

hi all

i have a sp from which i get result columns  gender,percentage,studentcount,year

my sp is like this..

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[usp_GetState]') AND type in (N'P'))
DROP PROCEDURE usp_GetState
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[usp_GetState]
(	@ExamYear Smallint
	,@ExamType Nvarchar(10)
)
AS
	
BEGIN

SET NOCOUNT ON;


	WITH cte_Schools AS
	(
		SELECT 
			[Foreign]= CASE WHEN M.Zone ='F' THEN 'Y' ELSE 'N' END
			,CASE WHEN M.Zone ='F' THEN UPPER(C.CountryName) ELSE UPPER(S.StateName) END StateName
			,COUNT( DISTINCT M.SchoolCode) Schools 
			,SUM( M.Nos) Students

		FROM rptFinalResultSummaryMaster M  
			LEFT OUTER JOIN State S ON M.StateCode=S.StateCode AND M.Zone=UPPER(LEFT(S.Zone,1))
			LEFT OUTER JOIN Country C ON S.CountryId= C.CountryId
		 WHERE M.Year=@ExamYear AND M.CourseCode=@ExamType
		 GROUP BY 	CASE WHEN M.Zone ='F' THEN 'Y' ELSE 'N' END
					,CASE WHEN M.Zone ='F' THEN UPPER(C.CountryName) ELSE UPPER(S.StateName) END
					
	)
	SELECT
		SlNo=ROW_NUMBER() OVER(PARTITION BY [Foreign] ORDER BY StateName)
		,[Foreign] 	,StateName, Schools,  Students
		, Percentage = (Students/(SELECT SUM(Students)*1.000 FROM cte_Schools))*100
	FROM cte_Schools
	ORDER BY [Foreign],StateName


END

GO

now..i wrote formula for percentage  and when i connected this sp to my rdl where i took tablixi gave percentage value to gender and total percentage column

                                       gender(column group)                       total

                                                                                           number   percentage

passcategory         


this is my tablix format

my output looks like

                                                                                boys     girls                                      total

                                                                                                                                 number(percentage)

passcategory1  (percenatge)                        21 (40.38)          43 (56.75)                 64(48.56)          

passcategory2   (percenatge)                       11  (21.15)         10    (13.51)               31(17.33)

passcategory3    (percentage)                       20 (38.46)         21    (28.37)               41(33.41)

total                     (percentage)                      52(xxx)           74  (xxx)                     136   (100%)

i'm not getting thegender percentage properly for girls and boys total percentage of boys and girls coming correctly but individual percentage is not properly coming...that's because in sp i gave calculation for only total percenatge ..how can i calculate the individual percentage of girls and boys in single column...so that i can place in gender column in tablix..and i can retrieve individual percentgaes of girls and boys seperately as shown in output..

please reply..its urgent

thanks in advance..


lucky


Viewing all articles
Browse latest Browse all 12844

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>