• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 406
  • Last Modified:

How do I best add a row count in a footer with a union

I have a file that is layed out as follows: HEADER, DETAILS, FOOTER

There is a union between all 3 as the header and footer are 2 and 5 columns respectively, and the details section has 35.

I'm trying to get a row count from the details section into the footer, but can't figure out a better way than copying the entire details into the footer, doing a row count on that, and modifying the output footer to include it. My details section is over 1000 lines long and uses 76 tables. I'd rather not have it take twice as long to run if there's a better way of going about doing this.

Any ideas?
0
chevere
Asked:
chevere
  • 7
  • 4
3 Solutions
 
slightwv (䄆 Netminder) Commented:
What tool?

I straight sql you can use a union.

Select col1, col2 from
(
Select 1
Sort_order, 'header' col1, null col2 from dual
Union all
Select 2, 'detail', 'some column' from table
Union all
Select 3, 'total', count(1) from table
) Order by sort_order
0
 
slightwv (䄆 Netminder) Commented:
Also in sqlplus you can compute totals, set headers, etc.
0
 
chevereAuthor Commented:
I'm using SQLPLUS
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
slightwv (䄆 Netminder) Commented:
So you want a sqlplus report?

Can you post a sample of what you are after?

Sample tables, sample data and expected results would be great.
0
 
chevereAuthor Commented:
Everything I have is in one column each (header, details, footer)

details is set up like:  Select LPAD(this,9,' ') || LPAD(that,9,' ') as details

Example:

Header1    03112011
John     Doe        XXXXXXXXX         High
Jane     Doe        XXXXXXXXX         High
Sam     Sample   XXXXXXXXX         Medium
Footer1      3    

(The 3 being a count of the details)

Could you use this logic to show me how this example would work inside the code layout you sent me?
0
 
slightwv (䄆 Netminder) Commented:
>>Can you post a sample of what you are after?

I should say, a simple sample.

For example you can COMPUTE the count.

See the sample below.

This is the output:
C
-
a
b
c
-
3

drop table tab1 purge;
create table tab1(col1 char(1));
insert into tab1 values('a');
insert into tab1 values('b');
insert into tab1 values('c');
commit;


clear breaks
clear computes
clear columns

set pages 100
compute count of col1 on report
break on report

select * from tab1;

Open in new window

0
 
slightwv (䄆 Netminder) Commented:
>>could you use this logic to show me how this example would work inside the code layout you sent me?

I was typing...

Will the compute above work for you?

0
 
chevereAuthor Commented:
I think so. So if I understand your example right, you're advising me to drop the data into a table (I'm assuming using an insert statement) and then do a query on the table with a union then a count (*) on the same table in the footer?

Ex:

Header -  stuff
Details - Query on data now in table (possibly a temp table)
Footer - Count from table with data

Or am I missing the mark?
0
 
slightwv (䄆 Netminder) Commented:
>>you're advising me to drop the data into a table

NO.  Since I don't have your 1000 line select statement over 76 tables and 35 columns, to show the 'concept' I need to create my own test case.

I dummied up a table to show the power of the COMPUTE statements.  You need to apply that concept to your situation.

Also below is a possible alternative.  Same basic results, different method.
drop table tab1 purge;
create table tab1(col1 char(1), col2 char(1));
insert into tab1 values('a','1');
insert into tab1 values('b','2');
insert into tab1 values('c','3');
commit;

set verify off
clear columns
column myTotal new_value some_var_name
column myTotal noprint

--turn off column headings
set pages 0

select 'Some Header' from dual;

Select col1, col2, count(*) over() myTotal from tab1;

Select 'total', &some_var_name from dual;

Open in new window

0
 
slightwv (䄆 Netminder) Commented:
>>on the table with a union then a count (*) on the same table in the footer?

forgot to comment on this.

NO.  That was the very first example not knowing this was a SQLPLUS report.  forget that first post...
0
 
chevereAuthor Commented:
I get the concept now! I'll play with it, but it looks like it will do what I need it to do.

I've got to run right now, but will know by morning how this works.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now