Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7010085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:56:45+00:00 2026-05-27T21:56:45+00:00

I found the following in Stackoverflow and have been working with it to find

  • 0

I found the following in Stackoverflow and have been working with it to find the number of Patient Days each month. It works very well if I have both the Admit and Discharge dates.

I can’t figure out how to edit it to calculate the Patient days when the discharge date has not been completed… the patient is still in the hospital. If feels like I should use Coalesce or ISNULL to find the records where the Discharge Date is NULL, but I’m not a programmer and would appreciate your help.

WITH Mos AS (
  SELECT
  D.ED_ADMIT_DATE,
  D.ED_DISCHARGE_DATE,
  Number,

  DateAdd(Month, Number, D.ED_ADMIT_DATE - Day(D.ED_ADMIT_DATE) + 1) MoDate
 FROM
  cases_cstm D
  INNER JOIN master.dbo.spt_values V ON V.Number <= DateDiff(Month, D.ED_ADMIT_DATE,  D.ED_DISCHARGE_DATE)
WHERE
  V.Type = 'P'), Dys AS (
SELECT
  MoDate,
  DateDiff(
     Day,
     CASE WHEN Number = 0 THEN ED_ADMIT_DATE ELSE MoDate END,
     CASE WHEN Number = DateDiff(Month, ED_ADMIT_DATE, ED_DISCHARGE_DATE) THEN  ED_DISCHARGE_DATE ELSE DateAdd(Month, 1, MoDate) -1 
 END
  ) + 1 Cnt
FROM Mos)
 SELECT  Year(MoDate) Yr,
 Coalesce(DateName(Month, MoDate), 'Total') Mo,
 Convert(varchar(11), Sum(Cnt)) + ' day' + CASE WHEN Sum(Cnt) = 1 THEN '' ELSE 's' END Descr

FROM Dys
GROUP BY  MoDate
WITH ROLLUP
ORDER BY
Grouping(MoDate),
MoDate;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:56:45+00:00Added an answer on May 27, 2026 at 9:56 pm

    You could replace each occurance of ED_DISCHARGE_DATE with:

    IsNull(ED_DISCHARGE_DATE,getdate())
    

    This uses the current time whenever the discharge date is unavailable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm very new to Ruby on Rails, and have been getting the following error
I haven't been able to adapt the examples I have found in stackoverflow that
I have been looking over StackOverflow and have not found any answers yet, if
On the MSDN, I have found following: public event EventHandler<MyEventArgs> SampleEvent; public void DemoEvent(string
I found the following rather strange. Then again, I have mostly used closures in
I have browsed StackOverflow and found a couple questions/answers that are close but not
I want to set up a Mercurial SC server and have been following the
I have been following the official Android tutorials and somehow am having a problem
Reading through documentation, I found following: 1.9.1 1.8.4 1.8.2 A version of 1.8.2 select
Found the following in an Oracle-based application that we're migrating (generalized) : SELECT Table1.Category1,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.