Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-server-2005 , +
hi
i created one query to get total amount from different table
 
here is my query
 
@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 27-Feb-13 19:42pm
ythisbug2.1K
Edited 27-Feb-13 19:43pm
v2

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



Advertise | Privacy | Mobile
Web04 | 2.8.1411022.1 | Last Updated 28 Feb 2013
Copyright © CodeProject, 1999-2014
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