Click here to Skip to main content
15,884,083 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi I am Working on a GridView which Displays the values from the below query,and I need to get the Total of each row at its footer

something like this:
R1 A B
R2 5 6
R3 1 11
tot 6 17

What I have tried:

;with t1 as (
SELECT DeptID, COUNT(EmpID) AS TotalHeadCount  FROM EmployeeDetails          
WHERE (datepart(yyyy,DOJ) between 2005 and @years) and Status =0
group by DeptID
),
t2 as (
SELECT  DeptID,COUNT(EmpID) AS NewJoinees FROM EmployeeDetails AS EmployeeDetails_7        
WHERE (DATEPART(yyyy, DOJ) = @years) AND (DATEPART(mm, DOJ)  = @months) and datepart(mm,DOJ)>= @months and Status = 0
group by DeptID
),
t3 as (
SELECT   DeptID,COUNT(EmpID) AS Resigned FROM  EmployeeDetails AS EmployeeDetails_7                           
WHERE (DATEPART(yyyy, deactivate) = @years) AND (DATEPART(mm, deactivate)  = @months) and datepart(mm,deactivate)>= @months and Status =1 group by DeptID
),
t4 as (
Select Distinct DeptID,Tobehired As ToBeHired,Openposition As OpenPositions,Status As Status1 From RecruitmentDetails1
WHERE Tobehired=45 
)
 
Select t1.DeptID, CASE WHEN TotalHeadCount IS NULL THEN '0' ELSE TotalHeadCount END AS TotalHeadCount,CASE WHEN NewJoinees IS NULL THEN '0' ELSE NewJoinees END AS NewJoinees,CASE WHEN Resigned IS NULL THEN '0' ELSE Resigned END AS Resigned, t4.Tobehired as ToBeHired, t4.OpenPositions as OpenPositions, t4.Status1 as Status1
from t1 full outer join t2 on t1.DeptID = t2.DeptID
full outer join t3 on t1.DeptID = t3.DeptID
full outer join t4 on t1.DeptID = t4.DeptID 
Posted
Updated 4-May-17 2:57am
Comments
Nirav Prabtani 4-May-17 8:48am    
I think you have posted same at

https://www.codeproject.com/Questions/1185372/How-to-write-insert-and-select-query-in-table-in-C
CHill60 4-May-17 8:55am    
That's a different question - I don't understand the question, but it's definitely different :)
Nirav Prabtani 4-May-17 9:01am    
Actually he/she want to display total at a bottom of gridview using boundfield,
His/her way of asking question is different but the question is same.
CHill60 4-May-17 9:07am    
We must be looking at different posts - the post in your link is about inserting and selecting data, nothing mentioned at all about totals at the bottom of a gridview. The code they have posted is the same.
Nirav Prabtani 4-May-17 9:33am    
Surrender !!! :)

Any way the post

https://www.codeproject.com/Answers/1185413/Insert-records-using-unique-key

has been closed due to we misunderstood an actual issue

it has been closed before OP can reach over the exact solution which is given in answer section

In this case what can be the resolution?

I dont know where to ask this kind of stuff so I am asking directly here.

1 solution

One of these Codeproject Search results[^] should be what you are after
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900