Click here to Skip to main content
13,505,219 members
Rate this:
Please Sign up or sign in to vote.
hi i created one query to get total amount from different table

here is my query

@Name varchar(50)
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

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 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 trying difficult..please suggest me.if u have doubt in my question please comment..
hope u understood..

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

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.180417.1 | Last Updated 28 Feb 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100