Presentation is loading. Please wait.

Presentation is loading. Please wait.

Reports Using SQL Script Please check speaker notes for additional information!

Similar presentations


Presentation on theme: "Reports Using SQL Script Please check speaker notes for additional information!"— Presentation transcript:

1 Reports Using SQL Script Please check speaker notes for additional information!

2 Report script SQL> edit rptslide1 This will bring up the editor (Notepad) so I can create a new script or edit an existing script with the name rptslide1. These are the column/field names that I want to appear in the report. These are the column headings. The bar between the words causes a break so the header will appear on two lines. In the notes, I repeatedly have the message Input truncated to 1 characters (sometimes a different number). The solution is to press ENTER after the / so you have a blank line. That avoids the message.

3 rptslide1 Empl Employee Start Id# Name Jo Date Salary Bonus Linda Costa CI 15-JAN John Davidson IN 25-SEP Susan Ash AP 05-FEB Stephen York CM 03-JUL Richard Jones CI 30-OCT Joanne Brown IN 18-AUG Donald Brown CI 05-NOV Paula Adams IN 12-DEC rows selected. Reports CLEAR COLUMNS COLUMN pay_id HEADING 'Employee|Id#' COLUMN name HEADING 'Employee|Name' COLUMN jobcode HEADING 'Job Code' COLUMN startdate HEADING 'Start|Date' COLUMN salary HEADING 'Salary' COLUMN bonus HEADING 'Bonus' / COLUMN is followed by the name of the column/field from the table that is going to be used. HEADING gives the column heading. Note that the bar between words in heading separates the words onto two means to execute - the code is named rptslide1

4 SQL> SELECT * FROM donor; Employee IDNO Name STADR CITY ST ZIP DATEFST YRGOAL CONTACT Stephen Daniels 123 Elm St Seekonk MA JUL John Smith Jennifer Ames 24 Benefit St Providence RI MAY Susan Jones Carl Hersey 24 Benefit St Providence RI JAN-98 Susan Jones Susan Ash 21 Main St Fall River MA MAR Amy Costa Nancy Taylor 26 Oak St Fall River MA MAR John Adams Robert Brooks 36 Pine St Fall River MA APR Amy Costa 6 rows selected. SQL> SELECT * FROM first_pay; Empl Employee Start Id# Name Jo Date Salary Bonus Linda Costa CI 15-JAN John Davidson IN 25-SEP Susan Ash AP 05-FEB Stephen York CM 03-JUL Richard Jones CI 30-OCT Joanne Brown IN 18-AUG Donald Brown CI 05-NOV Paula Adams IN 12-DEC rows selected. Reports Once the report has been executed, whatever table is used in the a SELECT will try to fit the table layout.

5 SQL> clear columns columns cleared SQL> SELECT * FROM first_pay; PAY_ NAME JO STARTDATE SALARY BONUS Linda Costa CI 15-JAN John Davidson IN 25-SEP Susan Ash AP 05-FEB Stephen York CM 03-JUL Richard Jones CI 30-OCT Joanne Brown IN 18-AUG Donald Brown CI 05-NOV Paula Adams IN 12-DEC rows selected. Reports Columns have been cleared so the column settings in the script are not used.

6 Reports CLEAR COLUMNS COLUMN pay_id HEADING 'Employee|Id#' COLUMN name HEADING 'Employee|Name' COLUMN jobcode HEADING 'Job Code' COLUMN startdate HEADING 'Start|Date' COLUMN salary HEADING 'Salary' COLUMN bonus HEADING 'Bonus' SELECT * FROM first_pay / SQL> edit rptslide2 This is rptslide2 as it appears in the editor (Notepad). rptslide2 Empl Employee Start Id# Name Jo Date Salary Bonus Linda Costa CI 15-JAN John Davidson IN 25-SEP Susan Ash AP 05-FEB Stephen York CM 03-JUL Richard Jones CI 30-OCT Joanne Brown IN 18-AUG Donald Brown CI 05-NOV Paula Adams IN 12-DEC rows rptslide2 runs the script which includes the SELECT so the output is produced.

7 Report rptslide3 Thu Jun 22 page 1 List of Employees Empl Employee Start Id# Name Jo Date Salary Bonus Linda Costa CI 15-JAN John Davidson IN 25-SEP Susan Ash AP 05-FEB Stephen York CM 03-JUL Richard Jones CI 30-OCT Joanne Brown IN 18-AUG Donald Brown CI 05-NOV Paula Adams IN 12-DEC rows selected. CLEAR COLUMNS COLUMN pay_id HEADING 'Employee|Id#' COLUMN name HEADING 'Employee|Name' COLUMN jobcode HEADING 'Job Code' COLUMN startdate HEADING 'Start|Date' COLUMN salary HEADING 'Salary' COLUMN bonus HEADING 'Bonus' SET LINESIZE 65 TTITLE 'List of Employees' SELECT * FROM first_pay / SQL> edit rptslide3 Rptslide3 as it came up in the editor when I keyed in edit rptslide3 at the SQL> Report that was generated SET LINESIZE can be used to establish the length of the line. TTITLE establishes a title for the report.

8 Report Thu Jun 22 page 1 List of Employees Employee Employee Job Start Id# Name Code Date Salary Bonus Linda Costa CI 15-JAN-97 $45, $1, John Davidson IN 25-SEP-92 $40, $1, Susan Ash AP 05-FEB-00 $25, $ Stephen York CM 03-JUL-97 $42, $2, Richard Jones CI 30-OCT-92 $50, $2, Joanne Brown IN 18-AUG-94 $48, $2, Donald Brown CI 05-NOV-99 $45, Paula Adams IN 12-DEC-98 $45, $2, rows selected. SQL> edit rptslide4 rptslide4 CLEAR COLUMNS COLUMN pay_id HEADING 'Employee|Id#' FORMAT A10 COLUMN name HEADING 'Employee|Name' FORMAT A20 COLUMN jobcode HEADING 'Job|Code' FORMAT A5 COLUMN startdate HEADING 'Start|Date' FORMAT A10 COLUMN salary HEADING 'Salary' FORMAT $999, COLUMN bonus HEADING 'Bonus' FORMAT $99, SET LINESIZE 80 TTITLE 'List of Employees' SELECT * FROM first_pay / FORMAT is used to establish the length of the filed or to format using special characters in the numeric fields shown.

9 Reports Thu Jun 22 page 1 List of Employees Employee Employee Job Start Id# Name Code Date Salary Bonus Susan Ash AP 05-FEB-00 $25, $ Linda Costa CI 15-JAN-97 $45, $1, Donald Brown 05-NOV-99 $45, Richard Jones 30-OCT-92 $50, $2, Stephen York CM 03-JUL-97 $42, $2, John Davidson IN 25-SEP-92 $40, $1, Paula Adams 12-DEC-98 $45, $2, Joanne Brown 18-AUG-94 $48, $2, rows selected. CLEAR COLUMNS COLUMN pay_id HEADING 'Employee|Id#' FORMAT A10 COLUMN name HEADING 'Employee|Name' FORMAT A20 COLUMN jobcode HEADING 'Job|Code' FORMAT A5 COLUMN startdate HEADING 'Start|Date' FORMAT A10 COLUMN salary HEADING 'Salary' FORMAT $999, COLUMN bonus HEADING 'Bonus' FORMAT $99, SET LINESIZE 80 TTITLE 'List of Employees' BREAK ON jobcode SELECT * FROM first_pay ORDER BY jobcode / SQL> edit rptslide5 rptslide5 The table has to be ordered by jobcode if you want to break on jobcode.

10 CLEAR COLUMNS COLUMN pay_id HEADING 'Employee|Id#' FORMAT A10 COLUMN name HEADING 'Employee|Name' FORMAT A20 COLUMN jobcode HEADING 'Job|Code' FORMAT A5 COLUMN startdate HEADING 'Start|Date' FORMAT A10 COLUMN salary HEADING 'Salary' FORMAT $999, COLUMN bonus HEADING 'Bonus' FORMAT $99, SET LINESIZE 80 TTITLE 'List of Employees' BREAK ON jobcode SKIP 2 COMPUTE SUM OF salary ON jobcode COMPUTE SUM OF bonus ON jobcode SELECT * FROM first_pay ORDER BY jobcode / I have now added the COMPUTE statement which will compute the SUM of salary and the SUM of bonus based on the jobcode break. Reports

11 Thu Jun 22 page 1 List of Employees Employee Employee Job Start Id# Name Code Date Salary Bonus Susan Ash AP 05-FEB-00 $25, $ ***** sum $25, $ Linda Costa CI 15-JAN-97 $45, $1, Donald Brown 05-NOV-99 $45, Richard Jones 30-OCT-92 $50, $2, ***** sum $140, $3, Stephen York CM 03-JUL-97 $42, $2, ***** sum $42, $2, Thu Jun 22 page 2 List of Employees Employee Employee Job Start Id# Name Code Date Salary Bonus John Davidson IN 25-SEP-92 $40, $1, Paula Adams 12-DEC-98 $45, $2, Joanne Brown 18-AUG-94 $48, $2, ***** sum $133, $5, rows selected. The two SUMS are included based on jobcode break.

12 SQL> CREATE VIEW view_first_pay 2 AS 3 SELECT jobcode, pay_id, name, startdate, salary, bonus 4 FROM first_pay; View created. Reports CLEAR COLUMNS COLUMN pay_id HEADING 'Employee|Id#' FORMAT A10 COLUMN name HEADING 'Employee|Name' FORMAT A20 COLUMN jobcode HEADING 'Job|Code' FORMAT A5 COLUMN startdate HEADING 'Start|Date' FORMAT A10 COLUMN salary HEADING 'Salary' FORMAT $999, COLUMN bonus HEADING 'Bonus' FORMAT $99, SET LINESIZE 80 TTITLE 'List of Employees' BREAK ON jobcode SKIP 2 COMPUTE SUM OF salary ON jobcode COMPUTE SUM OF bonus ON jobcode SELECT * FROM view_first_pay ORDER BY jobcode / SQL> edit rptslide7 I would prefer to have jobcode appear first in my report, so I created a view called view_first_pay from first_pay and put jobcode in as the first column. Then I went into rptslide7 (shown below) and changed the SELECT to use view_first_pay.

13 Reports Thu Jun 22 page 1 List of Employees Job Employee Employee Start Code Id# Name Date Salary Bonus AP 3333 Susan Ash 05-FEB-00 $25, $ ***** sum $25, $ CI 1111 Linda Costa 15-JAN-97 $45, $1, Donald Brown 05-NOV-99 $45, Richard Jones 30-OCT-92 $50, $2, ***** sum $140, $3, CM 4444 Stephen York 03-JUL-97 $42, $2, ***** sum $42, $2, Thu Jun 22 page 2 List of Employees Job Employee Employee Start Code Id# Name Date Salary Bonus IN 2222 John Davidson 25-SEP-92 $40, $1, Paula Adams 12-DEC-98 $45, $2, Joanne Brown 18-AUG-94 $48, $2, ***** sum $133, $5, rows selected. Note that jobcode is now in the first column.

14 CLEAR COLUMNS COLUMN pay_id HEADING 'Employee|Id#' FORMAT A10 COLUMN name HEADING 'Employee|Name' FORMAT A20 COLUMN jobcode HEADING 'Job|Code' FORMAT A5 COLUMN startdate HEADING 'Start|Date' FORMAT A10 COLUMN salary HEADING 'Salary' FORMAT $999, COLUMN bonus HEADING 'Bonus' FORMAT $99, SET LINESIZE 80 TTITLE 'List of Employees' BREAK ON REPORT COMPUTE SUM OF salary ON REPORT COMPUTE SUM OF bonus ON REPORT SELECT * FROM first_pay ORDER BY jobcode / Reports rptslide8 Thu Jun 22 page 1 List of Employees Employee Employee Job Start Id# Name Code Date Salary Bonus Susan Ash AP 05-FEB-00 $25, $ Linda Costa CI 15-JAN-97 $45, $1, Donald Brown CI 05-NOV-99 $45, Richard Jones CI 30-OCT-92 $50, $2, Stephen York CM 03-JUL-97 $42, $2, John Davidson IN 25-SEP-92 $40, $1, Paula Adams IN 12-DEC-98 $45, $2, Joanne Brown IN 18-AUG-94 $48, $2, sum $340, $11, rows selected. BREAK ON REPORT generates final totals.

15 Thu Jun 22 page 1 List of Employees Employee Employee Job Start Id# Name Code Date Salary Bonus Susan Ash AP 05-FEB-00 $25, $ Linda Costa CI 15-JAN-97 $45, $1, Donald Brown CI 05-NOV-99 $45, Richard Jones CI 30-OCT-92 $50, $2, Stephen York CM 03-JUL-97 $42, $2, John Davidson IN 25-SEP-92 $40, $1, Paula Adams IN 12-DEC-98 $45, $2, Joanne Brown IN 18-AUG-94 $48, $2, avg $42, maximum $2, Reports CLEAR COLUMNS COLUMN pay_id HEADING 'Employee|Id#' FORMAT A10 COLUMN name HEADING 'Employee|Name' FORMAT A20 COLUMN jobcode HEADING 'Job|Code' FORMAT A5 COLUMN startdate HEADING 'Start|Date' FORMAT A10 COLUMN salary HEADING 'Salary' FORMAT $999, COLUMN bonus HEADING 'Bonus' FORMAT $99, SET LINESIZE 80 TTITLE 'List of Employees' BREAK ON REPORT COMPUTE AVG OF salary ON REPORT COMPUTE MAX OF bonus ON REPORT SELECT * FROM first_pay ORDER BY jobcode /

16 CLEAR COLUMNS COLUMN pay_id HEADING 'Employee|Id#' FORMAT A10 COLUMN name HEADING 'Employee|Name' FORMAT A20 COLUMN jobcode HEADING 'Job|Code' FORMAT A5 COLUMN startdate HEADING 'Start|Date' FORMAT A10 COLUMN salary HEADING 'Salary' FORMAT $999, COLUMN bonus HEADING 'Bonus' FORMAT $99, SET LINESIZE 80 TTITLE 'List of Employees' BREAK ON REPORT ON jobcode SKIP 2 COMPUTE SUM OF salary ON jobcode COMPUTE SUM OF bonus ON jobcode COMPUTE SUM OF salary ON REPORT COMPUTE SUM OF bonus ON REPORT SELECT * FROM view_first_pay ORDER BY jobcode / Reports This is rptslide10 as it appears in the editor. Note that it has break on report and jobcode and that it has totals for both. On the BREAK line, the break that covers the most information (REPORT) is listed first and then the break that covers a smaller group of information (jobcode) is listed next.

17 rptslide10 Fri Jun 23 page 1 List of Employees Job Employee Employee Start Code Id# Name Date Salary Bonus AP 3333 Susan Ash 05-FEB-00 $25, $ ***** sum $25, $ CI 1111 Linda Costa 15-JAN-97 $45, $1, Donald Brown 05-NOV-99 $45, Richard Jones 30-OCT-92 $50, $2, ***** sum $140, $3, CM 4444 Stephen York 03-JUL-97 $42, $2, ***** sum $42, $2, Fri Jun 23 page 2 List of Employees Job Employee Employee Start Code Id# Name Date Salary Bonus IN 2222 John Davidson 25-SEP-92 $40, $1, Paula Adams 12-DEC-98 $45, $2, Joanne Brown 18-AUG-94 $48, $2, ***** sum $133, $5, sum $340, $11, Reports

18 SHOW ALL SQL> SHOW ALL appinfo is ON and set to "SQL*Plus" arraysize 15 autocommit OFF autoprint OFF autotrace OFF blockterminator "." (hex 2e) btitle OFF and is the 1st few characters of the next SELECT statement closecursor OFF cmdsep OFF colsep " " compatibility NATIVE concat "." (hex 2e) copycommit 0 copytypecheck is ON crt "" define "&" (hex 26) echo OFF editfile "afiedt.buf" embedded OFF escape OFF feedback ON for 6 or more rows flagger OFF flush ON heading ON headsep "|" (hex 7c) linesize 80 lno 25 long 80 longchunksize 80 maxdata newpage 1 non-blocking ON null "" numformat "" numwidth 9

19 pagesize 24 pause is OFF pno 2 recsep WRAP recsepchar " " (hex 20) release repfooter OFF and is NULL repheader OFF and is NULL serveroutput OFF showmode OFF spool OFF sqlcase MIXED sqlcode 0 sqlcontinue "> " sqlnumber ON sqlprefix "#" (hex 23) sqlprompt "SQL> " sqlterminator ";" (hex 3b) suffix "SQL" tab ON termout ON time OFF timing OFF trimout ON trimspool OFF ttitle ON and is the following 17 characters: List of Employees underline "-" (hex 2d) user is "SCOTT" verify ON shiftinout INVISIBLE wrap : lines will be wrapped SHOW ALL

20 SQL> clear columns columns cleared SQL> clear breaks breaks cleared SQL> ttitle off SQL> SELECT * FROM first_pay; PAY_ NAME JO STARTDATE SALARY BONUS Linda Costa CI 15-JAN John Davidson IN 25-SEP Susan Ash AP 05-FEB Stephen York CM 03-JUL Richard Jones CI 30-OCT Joanne Brown IN 18-AUG Donald Brown CI 05-NOV Paula Adams IN 12-DEC rows selected. Clearing report environment. Once you have created the report type environment using the report script you have to reverse it to return to get the ordinary results from the SELECT * FROM first_pay; type of command. As shown this can be done with clear columns and clear breaks and with turning features from the SHOW ALL list off or on as needed.

21 SQL> COLUMN salary HEADING 'Salary' FORMAT $999, SQL> SELECT * FROM first_pay; PAY_ NAME JO STARTDATE Salary BONUS Linda Costa CI 15-JAN-97 $45, John Davidson IN 25-SEP-92 $40, Susan Ash AP 05-FEB-00 $25, Stephen York CM 03-JUL-97 $42, Richard Jones CI 30-OCT-92 $50, Joanne Brown IN 18-AUG-94 $48, Donald Brown CI 05-NOV-99 $45, Paula Adams IN 12-DEC-98 $45, rows selected. Environment With this setting I am saying that this is the format I want used for any column named salary. The table doesn’t matter, it is the column name salary that has been given a heading and formatting.

22 SQL> COLUMN pay_id HEADING 'Pay Id #' FORMAT A10 SQL> SELECT * FROM first_pay; Pay Id # NAME JO STARTDATE Salary BONUS Linda Costa CI 15-JAN-97 $45, John Davidson IN 25-SEP-92 $40, Susan Ash AP 05-FEB-00 $25, Stephen York CM 03-JUL-97 $42, Richard Jones CI 30-OCT-92 $50, Joanne Brown IN 18-AUG-94 $48, Donald Brown CI 05-NOV-99 $45, Paula Adams IN 12-DEC-98 $45, rows selected. environment In this example, I have increased the size of the column where the pay_id will be displayed. I have also changed the heading. This would apply to any table with a column/field called pay_id.


Download ppt "Reports Using SQL Script Please check speaker notes for additional information!"

Similar presentations


Ads by Google