Wednesday, January 18, 2017

Query to retrieve account from meter id in CCB

SELECT AC.ACCT_ID
FROM CI_MTR MTR
INNER JOIN CI_MTR_CONFIG CNF
ON (MTR.MTR_ID = CNF.MTR_ID
AND MTR.MTR_ID = 0000084706)-- put your mtr id here
INNER JOIN CI_SP_MTR_HIST HIST
ON (CNF.MTR_CONFIG_ID = HIST.MTR_CONFIG_ID
AND TRIM(HIST.REMOVAL_MR_ID) IS NULL) --When you have to retrieve the meter which is installed on sp this field will be null
INNER JOIN CI_SP SP
ON(HIST.SP_ID = SP.SP_ID)
INNER JOIN CI_SA_SP SASP
ON (SP.SP_ID = SASP.SP_ID)
INNER JOIN CI_SA SA
ON(SASP.SA_ID = SA.SA_ID
AND SA.SA_STATUS_FLG = '20')--for retrieval of active SA's
INNER JOIN CI_ACCT AC
ON(SA.ACCT_ID = AC.ACCT_ID);

No comments:

Post a Comment