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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 PLS I NEED HELP WITH CHECK KEY VALIDATIONS
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Tijesuni
Starting Member

Nigeria
4 Posts

Posted - 03/16/2013 :  09:16:02  Show Profile  Reply with Quote
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

Romania
545 Posts

Posted - 03/16/2013 :  12:07:13  Show Profile  Reply with Quote
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

Romania
545 Posts

Posted - 03/16/2013 :  12:09:38  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000