Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 PLS I NEED HELP WITH CHECK KEY VALIDATIONS

Author  Topic 

Tijesuni
Starting Member

4 Posts

Posted - 2013-03-16 : 09:16:02
I have these tables

MANAGEMENT.PAYMENTS
PaymentID
PatientID
AdvancePayment
FinalPayment
PaymentStatus

FACILITIES.WARDDETAILS
WardID
WardName
Ward_Charge

PATIENTS.PATIENTDETAILS
PatientID
Discharge_Date
Admit_Date
Ward_ID

Pls how do i validate

1)FinalPayment should store the final amount chargeable and must be calculated as
Total Bill - AdvancePayment
3)The total bill will be calculated at time of discharge by adding the ward charges for the number of days the patient was admitted to the ward

stepson
Aged Yak Warrior

545 Posts

Posted - 2013-03-16 : 12:07:13
Hello
I guess about ManagementPayment, is one per patient per session.

not tested


select patientID
, datediff(d,discharge_Date,Admit_date) * Ward_Charge as [Total Bill]
, datediff(d,discharge_Date,Admit_date) * Ward_Charge-coalesce(AdvancePayment,0) as FinalPayment
from Patients.PatientDetails as PD
inner join Facilities.WardDetails as WD
on PD.Ward_ID=WD.Ward_ID
inner join Management.Payments MP
on PD.PatientID=MP.PatientID

Ce-am pe mine am si-n dulap, cand ma-mbrac zici ca ma mut
sabinWeb
Go to Top of Page

stepson
Aged Yak Warrior

545 Posts

Posted - 2013-03-16 : 12:09:38
it will be nice , if where some samples date, for better understand the relation between tables , especially ManagementPayment

S

Ce-am pe mine am si-n dulap, cand ma-mbrac zici ca ma mut
sabinWeb
Go to Top of Page
   

- Advertisement -