I need to produce an MS SQL Server query to count the number of days that a patient has been admitted for the current month however the issue I have is working out how to do this when a patient may have been admitted for months previous.
I've tried to use DATEDIFF to work out the number of days but can only get the total number of days from admission to discharge or the current date if they have not been discharged yet.
I have a single table that contains the admission details:
PatientID AdmissionDate DischargeDate WardID
Example:
- Patient admitted on 01/01/2019
- Patient discharged on 10/03/2019
- Report run for Feb and would return that the patients was admitted 28 days through Feb.