Hi,
I have this query that displays the detail records first and then the summary records:
select
'10' || '050' || '1234512345' ||
rpad(substr(a.check_number, 2, 10) || ' ', 10) ||
rpad(to_char(a.check_date, 'yyyymmdd') || ' ', 8)||
rpad(lpad(trunc(a.check_amt * 100, 0), 11, '0') || ' ', 11)||
rpad(' ',15) ||
decode(a.check_recon_status, 'V', 'V',' ')||
rpad(' ',80) as col1
from table a, table b
where a.tran_id = b.tran_id
and a.check_recon_date = sysdate
Union
select '20' || '050' || '1234512345' ||
lpad(count(a.check_number),10,0)||
rpad(to_char(a.check_date, 'yyyymmdd') || ' ', 8) ||
rpad(lpad(trunc(sum(a.check_amt) * 100, 0), 11, '0') || ' ', 107) as col2
from table a, table b
where a.tran_id = b.tran_id
and a.check_recon_date = sysdate
group by a.check_date
Union
select '30' || '050' || '9999999999' ||
lpad(count(a.check_number),10,0)||
rpad(to_char(a.check_date, 'yyyymmdd') || ' ', 8) ||
rpad(lpad(trunc(sum(a.check_amt) * 100, 0), 11, '0') || ' ', 107) as col3
from table a, table b
where a.tran_id = b.tran_id
and a.check_recon_date = sysdate
group by a.check_date;
Now, when there is a check that has a check date which is different from the check recon date then the grouping fails and it shows multiple summary records at the end..for example ..we had a scenario where the check recon date is different from the check date and it showed data as follows:
10048748079320200000106052008011800000007988 V
10048748079320200000108632008040900000002500
10048748079320200000108642008040900000065942
10048748079320200000108652008040900000005500
10048748079320200000108662008040900000125000
10048748079320200000108672008040900000004452
20048748079320200000000012008011800000007988
20048748079320200000000052008040900000203394
30048999999999900000000012008011800000007988
30048999999999900000000052008040900000203394
instead of
10050123451234500000106052008011800000007988 V
10050123451234500000108632008040900000002500
10050123451234500000108642008040900000065942
10050123451234500000108652008040900000005500
10050123451234500000108662008040900000125000
10050123451234500000108672008040900000004452
20050123451234500000000052008040900000211382
30050999999999900000000052008040900000211382
How do I make sure that it groups properly. Please advise.
Thanks.
I have this query that displays the detail records first and then the summary records:
select
'10' || '050' || '1234512345' ||
rpad(substr(a.check_number, 2, 10) || ' ', 10) ||
rpad(to_char(a.check_date, 'yyyymmdd') || ' ', 8)||
rpad(lpad(trunc(a.check_amt * 100, 0), 11, '0') || ' ', 11)||
rpad(' ',15) ||
decode(a.check_recon_status, 'V', 'V',' ')||
rpad(' ',80) as col1
from table a, table b
where a.tran_id = b.tran_id
and a.check_recon_date = sysdate
Union
select '20' || '050' || '1234512345' ||
lpad(count(a.check_number),10,0)||
rpad(to_char(a.check_date, 'yyyymmdd') || ' ', 8) ||
rpad(lpad(trunc(sum(a.check_amt) * 100, 0), 11, '0') || ' ', 107) as col2
from table a, table b
where a.tran_id = b.tran_id
and a.check_recon_date = sysdate
group by a.check_date
Union
select '30' || '050' || '9999999999' ||
lpad(count(a.check_number),10,0)||
rpad(to_char(a.check_date, 'yyyymmdd') || ' ', 8) ||
rpad(lpad(trunc(sum(a.check_amt) * 100, 0), 11, '0') || ' ', 107) as col3
from table a, table b
where a.tran_id = b.tran_id
and a.check_recon_date = sysdate
group by a.check_date;
Now, when there is a check that has a check date which is different from the check recon date then the grouping fails and it shows multiple summary records at the end..for example ..we had a scenario where the check recon date is different from the check date and it showed data as follows:
10048748079320200000106052008011800000007988 V
10048748079320200000108632008040900000002500
10048748079320200000108642008040900000065942
10048748079320200000108652008040900000005500
10048748079320200000108662008040900000125000
10048748079320200000108672008040900000004452
20048748079320200000000012008011800000007988
20048748079320200000000052008040900000203394
30048999999999900000000012008011800000007988
30048999999999900000000052008040900000203394
instead of
10050123451234500000106052008011800000007988 V
10050123451234500000108632008040900000002500
10050123451234500000108642008040900000065942
10050123451234500000108652008040900000005500
10050123451234500000108662008040900000125000
10050123451234500000108672008040900000004452
20050123451234500000000052008040900000211382
30050999999999900000000052008040900000211382
How do I make sure that it groups properly. Please advise.
Thanks.