/*
 * rc_matchsummaryjoin_dbio.pgc - 대사와 요약 조인 (rc_matchsummaryjoin_dbio), librcdbio.a.
 * ECPG; rc_match_log 를 rc_summary 와 biz_date INNER JOIN 하여 요약행이 존재하는 날의
 * MATCHED 금액 합을 구한다.
 */
#include <string.h>
#include <userlog.h>
#include "rc_matchsummaryjoin_dbio.h"

long rcdb_join_summary_gross(const char *bizdate)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_bizdate[16];
    long h_v = 0;
    EXEC SQL END DECLARE SECTION;
    strncpy(h_bizdate, bizdate, sizeof(h_bizdate)-1); h_bizdate[sizeof(h_bizdate)-1] = 0;
    EXEC SQL SELECT coalesce(sum(m.amount), 0) INTO :h_v
        FROM rc_match_log m
        JOIN rc_summary s ON s.biz_date = m.biz_date
        WHERE m.biz_date = :h_bizdate AND m.status = 'MATCHED';
    if (sqlca.sqlcode < 0) { userlog("rcdb_join_summary_gross FAIL [%d] %s", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); return -1; }
    return h_v;
}
