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 3981112
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:22:17+00:00 2026-05-20T05:22:17+00:00

Clarification Upon working through your answers and reading your interpretations of this question, I

  • 0

Clarification

Upon working through your answers and reading your interpretations of this question, I have the following to add.

  • I need to generate the entire BMI history, not a single value.
  • Every value in both tables needs to be paired (if possible) to a relevant value in the other table.

Simple Problem

Given an entry in PatientHeight, compute the BMI(Body Mass Index) with all entries in PatientWeight whose EntryDate falls between the current PatientHeight EntryDate and the previous PatientHeight EntryDate. This is true unless there are EntryDates in PatientWeight that are > then any EntryDates in PatientHeight. In this case, use the latest PatientHeight entry to compute the BMI.

For every entry in PatientHeight, compute the BMI(Body Mass Index) with all the appropriate corresponding values in PatientWeight.

Some Logic:

  • PatientHeight’s EntryDate is <= PatientWeight’s EntryDate when pairing
  • PatientHeight has a one to many relationship with PatientWeight
  • PatientHeight must take into account the EntryDate of the Previous PatientHeight and use it as a lower boundary when matching EntryDates in PatientWeight

I have a function to compute BMI, it’s just a question of how best to pair the data from the two tables.

Note: This must be done via a stored procedure, and I cannot change the tables

PatientHeight
PersonID
EntryDate
Inches

9783 | 01/01/2010 | 75in 
9783 | 01/01/2009 | 74in

PatientWeight
PersonID
EntryDate
Pounds

9783 | 01/01/2011 | 179lbs
9783 | 01/01/2010 | 175lbs
9783 | 12/01/2010 | 174lbs
9783 | 11/01/2010 | 178lbs
9783 | 01/01/2009 | 174lbs
9783 | 12/01/2009 | 174lbs
9783 | 11/01/2009 | 178lbs

So

Aside from iterating over every row in PatientWeight and querying for applicable Entries in PatientHeight and then computing BMI, is there any sort of fancy join to pair up the data correctly?

This would be ideal:

9783 | 01/01/2011 | 75in | 178lbs
9783 | 01/01/2010 | 75in | 175lbs
9783 | 12/01/2010 | 75in | 174lbs
9783 | 11/01/2010 | 75in | 178lbs
9783 | 01/01/2009 | 74in | 174lbs
9783 | 12/01/2009 | 74in | 174lbs
9783 | 11/01/2009 | 74in | 178lbs

My final Query

Here’s the core of it anyway. Seems to be working so far.

Insert Into @PatientWeightRet
    Select 
        *
    From
    (
        Select
            TransactionID, 
            EncounterID, 
            EntryDate,
            ISNULL(CONVERT(NUMERIC(18,2),dbo.fnBmi(Inches, Pounds)), -1) AS BMI
        From
        (
            Select Distinct
                W.TransactionID,
                W.PatientID, 
                W.EntryDate,
                W.EncounterID,
                W.Pounds,
                ( -- For Every Weight
                    Select Top 1 --Get the first Entry
                        H.Inches
                    From
                        @PatientHeight AS H -- From Patient Height 
                    Where 
                        H.EntryDate <=  W.EntryDate-- Who's Date is less than or equal to the Weight Date
                        AND W.EntryDate >  -- and the Weight Date is greater than (the previous height date)
                        (
                            ISNULL
                            (
                                (
                                    Select Top 1 -- the first 
                                        EntryDate -- date
                                    From
                                        @PatientHeight -- from patientHeight
                                    Where
                                        EntryDate < H.EntryDate -- who's entry date is less than the current height date
                                    Order BY EntryDate Desc, TransactionID DESC
                                )
                            , '01/01/1800') -- if we're at the bottom, return really old date
                        )
                    Order By H.EntryDate Desc, H.TransactionID DESC
                ) AS Inches
            From
                PatientWeight AS W
            Where 
                PatientID = @PatientID 
                AND Active = 1
        ) tmp
    ) tmp2
    Where
        BMI != -1
    Order By EntryDate DESC, TransactionID DESC
  • 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-20T05:22:18+00:00Added an answer on May 20, 2026 at 5:22 am
    SELECT W.PersonID,
           W.EntryDate,
           (
               SELECT TOP 1 H.Inches
                   FROM PatientHeight AS H
                   WHERE W.PersonID = H.PersonId
                       AND H.EntryDate <= W.EntryDate
                   ORDER BY H.EntryDate DESC
           ) AS Inches
           W.Pounds
        FROM PatientWeight AS W
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just need some quick clarification I have 2 Queries in my Access Database that
I need some clarification. I have a Reportwriter dll that uses Crystal Reports. It
This is a clarification question I've got from a Java EE 5 migration. I'm
I need clarification in calling methodologies, i have a base class and from which
Clarification: this question is not about access modifier Confirmed that B.m() and b.m() statements
Clarification/summary for the question -- we're looking for: a hosted bug tracking system, that
For clarification, are you able to use MySQL this way to sort? ORDER BY
I just need some clarification on variables A normal variable has 2 parts to
I just need clarification on what a managed prototype is. I think it is
(Followup to this question ) After surviving the first wave of incoming shipments (9

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.