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

SQL
SELECT     PatientReg.P_Id, PatientReg.PatientName, PatientReg.Age, PatientReg.ClinicalProb, PatientReg.Mobile, PatientReg.GuardianName, PatientReg.AdmitTime,
                      PatientReg.DPatientId, PatientReg.Relation, Bed.BedId, Bed.BedNo, InTreatment.Total, InTreatment.GTotal

FROM         PatientReg inner JOIN
                      Bed ON PatientReg.BedId = Bed.BedId inner JOIN
                      InTreatment ON PatientReg.P_Id = InTreatment.PatientId




Output is...................

14 Raju 12 serious 1234567890 ramu 24-10-2013 D00014 father 10 123 385 4385

14 Raju 12 serious 1234567890 ramu 24-10-2013 D00014 father 10 123 36 91

And I want The Out ............


14 Raju 12 serious 1234567890 ramu 24-10-2013 D00014 father 10 123 421 4476
Posted

Hi,

You can use Aggregate Functions of SQL. Check http://technet.microsoft.com/en-us/library/ms173454.aspx[^]

Best luck
-Amit
 
Share this answer
 
Comments
Parmendra choudhary 25-Oct-13 5:03am    
where we put the sum() function in Given query
AmitGajjar 25-Oct-13 5:05am    
use Gropu by and Sum. Check some examples.
Parmendra choudhary 25-Oct-13 5:03am    
can u give me changed query
AmitGajjar 25-Oct-13 5:04am    
I can't. that you need to learn. i can only give you idea.
SQL
SELECT     PatientReg.P_Id
         , 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.GTotal) AS 'InTreatmentGTotal'
FROM  PatientReg 
Inner JOIN Bed ON PatientReg.BedId = Bed.BedId 
Inner JOIN InTreatment ON PatientReg.P_Id = InTreatment.PatientId
Group By PatientReg.P_Id
           , PatientReg.PatientName
           , PatientReg.Age
           , PatientReg.ClinicalProb
           , PatientReg.Mobile
           , PatientReg.GuardianName
           , PatientReg.AdmitTime
           , PatientReg.DPatientId
           , PatientReg.Relation
           , Bed.BedId, Bed.BedNo
 
Share this answer
 
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