Click here to Skip to main content
11,789,706 members (63,383 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: SQL-server-2005 , +
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
Edited 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
0 OriginalGriff 999
1 Maciej Los 765
2 KrunalRohit 686
3 CPallini 606
4 Richard MacCutchan 430

Advertise | Privacy | Mobile
Web03 | 2.8.1509028.1 | Last Updated 28 Feb 2013
Copyright © CodeProject, 1999-2015
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