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

  • Home
  • SEARCH
  • 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 5985479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:32:09+00:00 2026-05-22T22:32:09+00:00

I run a report in mysql which returns all active members and their associated

  • 0

I run a report in mysql which returns all active members and their associated plan selections. If a member is terminated, this is displayed on the report as well. The issue I am facing, however is when a member simply decides to ‘change’ plans. Our system effective ‘terminates’ the original plan and starts fresh with the new one while keeping the original enrollment information for the member.

Sample report data may look like the following:

MemberID | Last    | First | Plan Code |  Original Effective | Change Date   |   Term Date
--------------------------------------------------------------------------------------------
12345    | Smith   | John  |     A     |   05-01-2011        |               |   06-01-2011
12345    | Smith   | John  |     B     |   06-01-2011        |               |      

In the example above, a member had plan code A from May 1, 2011 to June 1, 2011. On June 1, 2011, the member changed his coverage to Plan B (and is still active since no term or change data).

Ultimately, I need my report to generate the following instead of the 2 line items above:

MemberID | Last    | First | Plan Code |  Original Effective | Change Date   |   Term Date
--------------------------------------------------------------------------------------------
12345    | Smith   | John  |     B     |   05-01-2011        |  06-01-2011   | 

which shows his original plan effective date, the date of the change, and leaves the termination field blank.

I know I can get into a single row by using Group By the Member ID and I can even add the change date into the appropriate field with a (IF COUNT() > 1) statement but I am not able to figure out how to show the correct plan code (C) or how to leave the term date blank keeping the original effective date.

Any ideas?

  • 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-22T22:32:09+00:00Added an answer on May 22, 2026 at 10:32 pm

    Although I hate columns with embedded spaces and having to tick them, this should do it for you. The PreQuery will detect how many policy entries there are, preserve the first and last too, grouped by member. Once THAT is done, it can re-join the the plan enrollment on the same member but matching ONLY for the last “Original Effective” date for the person… That will give you the correct Plan Code. Additionally, if the person was terminated, it’s date would be filled in for you. If still employed, it will be blank on that record.

    select STRAIGHT_JOIN
          pe2.MemberID,
          pe2.Last,
          pe2.First,
          pe2.`Plan Code`
          PreQuery.PlanStarted `Original Effective`,
          case when PreQuery.PlanEntries > 1 then PreQuery.LastChange end `Change Date`,
          pe2.`Term Date`
       from
          ( select 
                  pe.MemberID,
                  count(*) as PlanEntries,
                  min( `pe`.`Original Effective` ) PlanStarted,
                  max( `pe`.`Original Effective`) LastChange
               from
                  PlanEnrollment pe
               group by
                  pe.MemberID ) PreQuery
    
         join PlanEnrollment pe2
            on PreQuery.MemberID = pe2.MemberID
            AND PreQuery.LastChange = pe2.`Original Effective`
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to run a cron job to backup some mysql databases by
I have a table in which approx 100,000 rows are added every day. I
We have a service which sees several hundred simultaneous connections throughout the day, peeking
When I add slow code to the OnChange event of TPageControl I run into
im trying to setup sqlite as a secondary adapter and have run into a
I have a report with a dataset of: select Field1, Field2, Field3, ... FieldN
I have developed a web application driven by a mysql database that stores information
I have a SQL Server 2005 .BAK file (created with a maintenance plan) that
Aloha everyone, I apologize in advance for the many questions, but I've been asked
I have three tables. Let's call them a, b, and a_to_b. a_to_b contains (among

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.