Have a sql server database that stores information about clients such as the date/month that the client initial became a client (initial client span) and the MktCode and PlanCode for the clients.
Sometimes the clients terminate service that is recorded in the field titled "ClientEndDt." If a client terminated and rejoins, the client will have another "elibility span" where there are additional values stored in the fields titled "ClientStartDt" and "ClientEndDt."
For example:
ClientID--ClientStartDt----MktCode---PlanCode
12345-----01/01/07---------LosAngel---Calif
12345-----06/16/07---------Seattle----Wash
So far, I am not able to extract the initial MktCode or PlanCode values for the clients using the sql script below.
What revisions do I need to make to the sql script so that the initial MktCode and PlanCode are in the query results?
Any assistance will be appreciated.
SELECT C.CLIENT_ID
, INIT_SPAN.ClientStartDt
, C.CLIENT_FIRST_NM
, CE.CLIENT_PLAN_CD PlanCode
, CE.CLIENT_MARKET_CD MktCode
FROM CLIENT C
INNER JOIN CLIENT_LOOKUP CL
ON C.CLIENT_ID = ML.CLIENT_ID
INNER JOIN CLIENT_ELIGIBILITY CE
ON C.CLIENT_ID = CE.CLIENT_ID
INNER JOIN
( --RETRIEVES INITIAL CLIENT SPAN
SELECT CLIENT_ID,
MIN(CLIENT_START_DT) AS InitialSpanDate
FROM CLIENT_ELIGIBILITY
WHERE CLIENT_PLAN_CD = ?
CLIENT_MARKET_CD = ?
GROUP BY CLIENT_ID
) INIT_SPAN
ON CE.CLIENT_ID = INIT_SPAN.CLIENT_ID
AND CE.CLIENT_START_DT = INIT_SPAN.InitialSpanDate
WHERE C.CLIENT_ID in ('458923','459826')
Sometimes the clients terminate service that is recorded in the field titled "ClientEndDt." If a client terminated and rejoins, the client will have another "elibility span" where there are additional values stored in the fields titled "ClientStartDt" and "ClientEndDt."
For example:
ClientID--ClientStartDt----MktCode---PlanCode
12345-----01/01/07---------LosAngel---Calif
12345-----06/16/07---------Seattle----Wash
So far, I am not able to extract the initial MktCode or PlanCode values for the clients using the sql script below.
What revisions do I need to make to the sql script so that the initial MktCode and PlanCode are in the query results?
Any assistance will be appreciated.
SELECT C.CLIENT_ID
, INIT_SPAN.ClientStartDt
, C.CLIENT_FIRST_NM
, CE.CLIENT_PLAN_CD PlanCode
, CE.CLIENT_MARKET_CD MktCode
FROM CLIENT C
INNER JOIN CLIENT_LOOKUP CL
ON C.CLIENT_ID = ML.CLIENT_ID
INNER JOIN CLIENT_ELIGIBILITY CE
ON C.CLIENT_ID = CE.CLIENT_ID
INNER JOIN
( --RETRIEVES INITIAL CLIENT SPAN
SELECT CLIENT_ID,
MIN(CLIENT_START_DT) AS InitialSpanDate
FROM CLIENT_ELIGIBILITY
WHERE CLIENT_PLAN_CD = ?
CLIENT_MARKET_CD = ?
GROUP BY CLIENT_ID
) INIT_SPAN
ON CE.CLIENT_ID = INIT_SPAN.CLIENT_ID
AND CE.CLIENT_START_DT = INIT_SPAN.InitialSpanDate
WHERE C.CLIENT_ID in ('458923','459826')