Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi i created one query to get total amount from different table

here is my query

SQL
@Name varchar(50)
AS BEGIN    SET NOCOUNT ON;
Select  tblAssetUnits.untCharges,tblAssetUnits.untFlat,tblCharge.cValue,tblCharge.cGheID,tblCharge.cID,tblGeneralHeader.gheChargeName,
(select sum(cValue)from tblCharge where tblCharge.cGheID=tblAssetUnits.untCharges)

from tblAssetUnits
Inner join
tblCharge on tblAssetUnits.untCharges=tblCharge.cGheID
left outer join tblGeneralHeader on tblAssetUnits.untCharges=tblGeneralHeader.gheID
    where   tblAssetUnits.untFlat  like @Name+'%'
order by tblAssetUnits.untFlat
END




in this line i want to do some changes
(select sum(cValue)from tblCharge where tblCharge.cGheID=tblAssetUnits.untCharges)



tblCharge contains
cGheID	int	
cApplication	varchar(50)	
cID	int	Unchecked
cChargeDetails	varchar(50)	
cFactor	int	Checked
cValue	decimal(18, 4)	
cDelStatus	bit	


and tblAssetUnits
untAssetUnitID	int	
untDescription	varchar(100)	
untFlat	varchar(50)	
untTypeID	int	Checked
untArea	decimal(18, 4)	
untUnits	varchar(50)	
untBR	varchar(50)	
untBathRoom	varchar(50)	
untGroupID	int	
unitRate	decimal(18, 4)	
untFloorPlan	varchar(50)	
untCharges	varchar(50)	



1. for ex. for 'Charge one' am adding 4 grid data with Fixed rate and Per Unit rate.
2.In tblAssetUnits am saving tblCharge id in untCharges.
3.Sum should calculate like in tblCharge cApplication is dropdown to select Fixed or PerUnit
4.here to sum like if it is Per Unit then cValue(tblCharge.cApplication is Per unit then tblAssetUnits.untArea*tblCharge.cValue) and if tblCharge.cApplication is Fixed then tblAssetUnitsuntArea+ tblCharge.cValue)

so how to get sum like this way..am trying difficult..please suggest me.if u have doubt in my question please comment..
hope u understood..

thank you..
Posted
Updated 27-Feb-13 18:43pm
v2

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