Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I am using two tables and get the o/p.

I have one column called salary in second table.

I want to calculate and sum of Total salary and display in one seperate column with total sum amount like below format.

See my query...
SQL
select T1.Code,T1.Serv.No,T2.ID,T2.Salary,sum(T2.Salary) asTotalSum from Table1 T1 left outer joinTable2 T2 on
T1.EmpCode=T2.EmpCode and T2.EmpNo= 'E001' group by T1.Code,T1.Serv.No,T2.ID,T2.Salary order
by T1.Code,T1.Serv.No,T2.ID,T2.Salary

Output
----------

Table 1 (T1)		Table2 (T2)		<br />
Code	Serv.No	         ID	Salary	Total<br />
F94134	PI4235INS	4235	NULL	2500 (Total Salary)<br />
F94150	PI4211PRO	4211	300	<br />
F94133	PI4234ELE	4234	900	<br />
F94135	PI4211PIP	4211	NULL	<br />
F94131	PI4237CIV	4237	800	<br />
F94120	PI3010PRT	3020	NULL	<br />
F94150	PI4223COM	4233	500	<br />
F94130	PI4221ENG	4221	NULL	<br />
F94150	PI4278ENV	4278	NULL	<br />
F94132	PI4211OST	4211	NULL	<br />
F94021	PI4010MPC	4010	NULL	<br />
F94030	PI1350QUA	1350	NULL	



I want to display in the above format in Total Column Sum.
How to do this..
.
Posted
Updated 23-Dec-11 1:50am
v5
Comments
Rajesh Anuhya 23-Dec-11 6:14am    
Not clear..

go through the below links

ROLLUP[^]

CUBE[^]
 
Share this answer
 
Comments
RaisKazi 23-Dec-11 8:34am    
My 5.
Hi,

if you are using SQL server 2008 , you can use Rollup to get Total of your query.

SQL
select T1.Code,T1.Serv.No,T2.ID,T2.Salary,sum(T2.Salary) asTotalSum from Table1 T1 left outer joinTable2 T2 on
T1.EmpCode=T2.EmpCode and T2.EmpNo= 'E001' group by T1.Code,T1.Serv.No,T2.ID,T2.Salary order
by T1.Code,T1.Serv.No,T2.ID,T2.Salary with rollup


there will be last line with total value.

hope this will help you.

thanks
-amit.
 
Share this answer
 
Comments
RaisKazi 23-Dec-11 8:34am    
My 5.
AmitGajjar 24-Dec-11 3:09am    
Thank you...
Refer this


sum of Total working hours

Thanks..
 
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