Link to home
Start Free TrialLog in
Avatar of britpopfan74
britpopfan74Flag for United States of America

asked on

Help with a derived table in an existing query

Hi Experts,

Need help with how to create a derived table within the query below.

The current query lists all of a hospital's primary diagnoses in ICD-9 code (e.g. V20.2, etc.), as well as counts and sums of claims for a designated time period.

What I'd like to add in is a description, ICD_9_Desc, so that when someone sees V20.2, it will pull from the ICD-9 table and see the code as well as that it's a "Well Child Visit".

The ICD_9 and ICD_9_DESC are in the ICD_9_CODES table.

Cannot figure out where I can reference this from within the query.

Thank you


SELECT FHC.PRIMARY_DIAGNOSIS
--insert ICD-9 description here
, COUNT(DISTINCT FHC.[DOCUMENT]) AS TOTAL_CLAIMS MASTER_CLAIM#DETAIL
, SUM(FHC.BILL_AMT) AS TOTAL_BILLED
, SUM(FHC.TOTAL_PAY_AMT) AS TOTAL_PAID
from #temp_eligibles D
LEFT JOIN FH_MASTER_CLAIM_VALID FHC ON D.MEM_NO = FHC.MEMBER
LEFT JOIN dbo.PHYSICIAN P ON FHC.PROVIDER = P.PROVIDER_ID
WHERE
(FHC.FIRST_DOS BETWEEN @FDOS AND @EFF_THRU)
GROUP BY FHC.PRIMARY_DIAGNOSIS
ORDER BY COUNT(DISTINCT FHC.[DOCUMENT]) DESC
ASKER CERTIFIED SOLUTION
Avatar of DBAduck - Ben Miller
DBAduck - Ben Miller
Flag of United States of America 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 britpopfan74

ASKER

Thank you - join worked.