Left join with same tables multiple times displaying the data into multiple rows

  • my requirements is to display the single record by for all the cases associated with patient

    i try to resolve this using max and CTE but this is removing records and displaying the latest record only

    I  need to show the records with in one row by patient .. but if that patient have multiple similar cases with same case type can display the duplicate records for same patient ...but when i tried max or CTE.. it eliminating the records

    Please see the attached data that my query is displaying(Sheet1) and also i attached the data that i need to display(sheet 2) .any suggestions/or pointer would help.

     

    • This topic was modified 5 years, 1 month ago by  sunitha 20026.
    Attachments:
    You must be logged in to view attached files.
  •  

    • This reply was modified 5 years, 1 month ago by  sunitha 20026.
  • Most people here won't open Excel documents from the Internet.

    Can you use text files, or simply cut & paste the code, instead?

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • I'm not at all sure what your requirement is but if you want to show multiple rows on one row then you need to use a FOR XML PATH statement to concatenate multiple rows for each patient, case type into one row.

     

  •  

    • This reply was modified 5 years, 1 month ago by  sunitha 20026.
    • This reply was modified 5 years, 1 month ago by  sunitha 20026.
  • I think you can do it by changing your LEFT JOINs to be OUTER APPLY and selecting TOP(1) within it.

      FROM #DataExtract t1
    OUTER APPLY(SELECT TOP(1) *
    FROM #DataExtract t2
    WHERE t2.case_number = t1.Case_Number
    AND t2.Case_Record_Type = 'General Inquiry'
    AND t2.Case_Sub_Type = 'Escalation') t2
    OUTER APPLY(SELECT TOP(1) *
    FROM #DataExtract t3
    WHERE t3.case_number = t1.Case_Number
    AND t3.Case_Record_Type = 'Follow Up 3 Step'
    AND t3.Case_Sub_Type = 'Escalation') t3
    OUTER APPLY (SELECT TOP(1) *
    FROM #DataExtract t4
    WHERE t4.case_number = t1.Case_Number
    AND t4.Case_Record_Type = 'Benefits Verification'
    AND (t4.BV_Processing_Mode IS NULL OR t4.BV_Processing_Mode = 'Manual')) t4
    OUTER APPLY (SELECT TOP(1) *
    FROM #DataExtract t5
    WHERE t5.case_number = t1.Case_Number
    AND t5.Case_Record_Type = 'Benefits Verification'
    AND t5.BV_Processing_Mode = 'Automated') t5
    OUTER APPLY (SELECT TOP(1) *
    FROM #DataExtract t6
    WHERE t6.case_number = t1.Case_Number
    AND t6.Case_Record_Type = 'Missing Information') t6
    OUTER APPLY (SELECT TOP(1) *
    FROM #DataExtract t7
    WHERE t7.case_number = t1.Case_Number
    AND t7.Case_Record_Type = 'Prior Authorization'
    AND t7.Case_Sub_Type <> 'Appeal') t7
    OUTER APPLY (SELECT TOP(1) *
    FROM #DataExtract t8
    WHERE t8.case_number = t1.Case_Number
    AND t8.Case_Record_Type = 'Prior Authorization'
    AND t8.Case_Sub_Type = 'Appeal') t8
    OUTER APPLY (SELECT TOP(1) *
    FROM #DataExtract t9
    WHERE t9.case_number = t1.Case_Number
    AND t9.Case_Record_Type = 'Commercial Copay') t9
    OUTER APPLY (SELECT TOP(1) *
    FROM #DataExtract t10
    WHERE t10.case_number = t1.Case_Number
    AND t10.Case_Record_Type = 'Claims Admin') t10;
  • You haven't said what you are using to display this information.  It may be (much) easier to do this in your presentation layer than the database layer.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply