Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My Query..............

SELECT PatientReg.PatientName, PatientReg.Age, PatientReg.ClinicalProb, PatientReg.Mobile, PatientReg.GuardianName, PatientReg.AdmitTime, PatientReg.DPatientId,
PatientReg.Relation, Bed.BedId, Bed.BedNo, SUM(InTreatment.Total) AS 'InTreatmentTotal', SUM(InTreatment.Price) AS 'InTreatmentPrice', PatientReg.P_Id,
EarlyPayment.Amount
FROM PatientReg INNER JOIN
Bed ON PatientReg.BedId = Bed.BedId INNER JOIN
InTreatment ON PatientReg.P_Id = InTreatment.PatientId INNER JOIN
EarlyPayment ON PatientReg.P_Id = EarlyPayment.IP_Id
WHERE (PatientReg.P_Id = '15') AND (PatientReg.InOut = 'I')
GROUP BY PatientReg.PatientName, PatientReg.Age, PatientReg.ClinicalProb, PatientReg.Mobile, PatientReg.GuardianName, PatientReg.AdmitTime, PatientReg.DPatientId,
PatientReg.Relation, Bed.BedId, Bed.BedNo, PatientReg.P_Id, EarlyPayment.Amount

OutPut............

Riya 22 trd 68767 hbbb 28-10-2013 D00015 bbbb 8 3 3540 186 15 44444
Riya 22 trd 68767 hbbb 28-10-2013 D00015 bbbb 8 3 3540 186 15 99999


but I want

Riya 22 trd 68767 hbbb 28-10-2013 D00015 bbbb 8 3 3540 186 15 144443
Posted
Comments
kankeyan 7-Nov-13 5:52am    
use derived tables

1 solution

SELECT PatientName, Age, ClinicalProb, Mobile, GuardianName, AdmitTime, DPatientId,
Relation, BedId, BedNo, InTreatmentTotal, InTreatmentPrice, P_Id,
Sum(Amount) from
(
SELECT PatientReg.PatientName, PatientReg.Age, PatientReg.ClinicalProb, PatientReg.Mobile, PatientReg.GuardianName, PatientReg.AdmitTime, PatientReg.DPatientId,
PatientReg.Relation, Bed.BedId, Bed.BedNo, SUM(InTreatment.Total) AS 'InTreatmentTotal', SUM(InTreatment.Price) AS 'InTreatmentPrice', PatientReg.P_Id,
EarlyPayment.Amount
FROM PatientReg INNER JOIN
Bed ON PatientReg.BedId = Bed.BedId INNER JOIN
InTreatment ON PatientReg.P_Id = InTreatment.PatientId INNER JOIN
EarlyPayment ON PatientReg.P_Id = EarlyPayment.IP_Id
WHERE (PatientReg.P_Id = '15') AND (PatientReg.InOut = 'I')
GROUP BY PatientReg.PatientName, PatientReg.Age, PatientReg.ClinicalProb, PatientReg.Mobile, PatientReg.GuardianName, PatientReg.AdmitTime, PatientReg.DPatientId,
PatientReg.Relation, Bed.BedId, Bed.BedNo, PatientReg.P_Id, EarlyPayment.Amount
) a
group by PatientName, Age, ClinicalProb, Mobile, GuardianName, AdmitTime, DPatientId,
Relation, BedId, BedNo, InTreatmentTotal, InTreatmentPrice, P_Id
 
Share this answer
 
Comments
Parmendra choudhary 7-Nov-13 5:59am    
Thanks u
kankeyan 7-Nov-13 6:05am    
Most Welcome
Parmendra choudhary 7-Nov-13 6:05am    
but if EarlyPayment table have no data then how we set amount=0 in our output
kankeyan 7-Nov-13 6:11am    
case when EarlyPayment.Amount='' then 0 else EarlyPayment.Amount END as Amount
use in inner table
Parmendra choudhary 7-Nov-13 6:12am    
ok

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