Link to home
Start Free TrialLog in
Avatar of GPSPOW
GPSPOWFlag for United States of America

asked on

Selecting data based on effective date

I have a table of the data appended every year based on the effective dates. of the changes.  The data changes once a year at 10/1 and is assigned a new version number.  The relevant fields in this table are Code, Version, Effective Date, Amount.

The second table is a list of customers who come in and have a service performed and are charged  a fee based on the current rate in the first table.

I want to match up the correct fee from the first table based on the date of service and the code charged.  

What is the syntax to obtain the correct amount where the Code service date is between the beginning and ending effective date of the correct version the first table?

Thanks

Glen
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

Just for kicks and giggles, please give us a data mockup of both tables, and an example or three of what you're trying to pull off.  Hard to conceptualize with just the description here.  tia
Avatar of GPSPOW

ASKER

I have attached sample data for the Customers and Rates.  I am trying to match up the correct ALOS and GLOS for each customer based where the Customer DischDate falls within the EffectiveDate and 9/30 of the following year from the effective date  and where the Customer DRG = Rate DRG for all 'MCR'  financial class types.

The Customer DRG has no leading zeros and the Rates DRG has leading zeros.  The field has a length of 3.


Here are 3 customers and their expected outcomes:

Customer #         DRG    DischDate     ALOS      GLOS
A10000415900    357    12/22/2014      6.6          5.1
A10000420628    439     1/16/2015      8.5           6.8
A10000429519    638     3/11/2015       3.7          3


Thanks
Glen
Sample-Data.xlsx
Avatar of GPSPOW

ASKER

Here is my solution:
SELECT     VisitID, AcctNumber, MedRecNumber, AdmDate, DischDate, AdmDt2, Days, LaceDate, LaceScore, DisYear, DisMonth, MRRank, Age, DC_DispID, 
                      DC_DISPDescr, FinancialClassName, Name, RoomID, LOS, Physician, DiagnosisName, 
MaritalStatus, Ethnicity, Zip, Language, DRG,
                          (SELECT     TOP (1) ALOS
                            FROM          dbo.vw_MedAssets_DRG_Tables AS t2
                            WHERE      (CONVERT(numeric(5, 0), t1.DRG) = CONVERT(numeric(5, 0), DRG)) AND (t1.DischDate >= BegDate) AND (t1.DischDate <= EndDate)) 
                      AS ALOS,
                          (SELECT     TOP (1) GLOS
                            FROM          dbo.vw_MedAssets_DRG_Tables AS t2
                            WHERE      (CONVERT(numeric(5, 0), t1.DRG) = CONVERT(numeric(5, 0), DRG)) AND (t1.DischDate >= BegDate) AND (t1.DischDate <= EndDate)) 
                      AS GLOS,


FacNote, ApptNote, FollowUpNote, BHIPNote, BHOPNote 
                      
FROM         dbo.vw_Lace_Discharge_Readmit_Days AS t1

Open in new window


Thanks

glen
What are the definition from vw_Lace_Discharge_Readmit_Days and vw_MedAssets_DRG_Tables?
ASKER CERTIFIED SOLUTION
Avatar of Vitor Montalvão
Vitor Montalvão
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of GPSPOW

ASKER

Thanks

Glen