You are on page 1of 32

Practical SQL

for the A/P Functional User

Steve Bradley
Atlanta OAUG
October 15, 1999

OASIS
Consulting Group, Inc.
Agenda
• SQL Overview
• Payables Tables
• Table Relationships
• Practical Examples
• T.O.A.D

OASIS
Consulting Group, Inc.
Steve Bradley sbradley@sprynet.com
SQL Overview - Select
• Select column_name1, column_name2, …
From table_name
Where criteria
– What are we going to do?
– What columns are we interested in?
• Select is (almost) always safe to use
– It never changes data
– It can tie up computer resources with large tables and
complex (inefficient) queries
OASIS
Consulting Group, Inc.
Steve Bradley sbradley@sprynet.com
Update
• Update table_name
Set (column_name1, column_name2, …)
= (value1, value2, …)
Where criteria

• Will change data!!!!


• May void Oracle Support!!!!
• Know what you are doing with this!!!

OASIS
Consulting Group, Inc.
Steve Bradley sbradley@sprynet.com
Delete
• Delete
From table_name
Where criteria

• Will delete data!!!!


• May void Oracle Support!!!!
• Know what you are doing with this!!!

OASIS
Consulting Group, Inc.
Steve Bradley sbradley@sprynet.com
From
• From table_name1, table_name2, ...
– What table(s) are we going to use?
– You can Select data from more than one table in a
query
– You can Update only one table at a time
(from is not used in Update)
– You can Delete from only one table at a time

OASIS
Consulting Group, Inc.
Steve Bradley sbradley@sprynet.com
Where
• Where criteria
– What is our selection criteria?

Where invoice_num = ‘12345’


and invoice_date = ‘14-JAN-99’
and PO_VENDOR.vendor_name = ‘ABC CORP’
and invoice_amount > 5000

OASIS
Consulting Group, Inc.
Steve Bradley sbradley@sprynet.com
Order by
• Order by column_name1, column_name2, ...
– How do we want it sorted?

Order by vendor_id, invoice_date, invoice_amount

OASIS
Consulting Group, Inc.
Steve Bradley sbradley@sprynet.com
Payables Tables
• Technical Reference Manual - TRM
– GL_CODE_COMBINATIONS
– PO_VENDORS
– PO_VENDOR_SITES_ALL
– AP_BATCHES_ALL
– AP_INVOICES_ALL
– AP_INVOICE_DISTRIBUTIONS
– AP_CHECKS_ALL

OASIS
Consulting Group, Inc.
Steve Bradley sbradley@sprynet.com
GL_CODE_COMBINATIONS
• The most used table in Oracle Applications
• Stores all AFF combinations
• Very few tables store actual segment values
• Almost all tables store CCID (code
combination ID) found in this table
• Any query displaying the AFF must Select
from this table
OASIS
Consulting Group, Inc.
Steve Bradley sbradley@sprynet.com
PO_VENDORS
• Stores most data keyed into the Supplier
setup form
– Vendor Name
– Vendor Number
– Vendor Type
– Tax info
– Terms

OASIS
Consulting Group, Inc.
Steve Bradley sbradley@sprynet.com
PO_VENDOR_SITES_ALL
• Stores most data keyed into the Sites form
– Site Name
– Address lines
– Site Terms
– Site PayGroup
– Org_ID

OASIS
Consulting Group, Inc.
Steve Bradley sbradley@sprynet.com
xxxxx_All Tables
• These are Multi-Org tables
• _All means there is a column named
Org_ID in the table
• This is why you cannot see Vendor sites
belonging to another Organization

OASIS
Consulting Group, Inc.
Steve Bradley sbradley@sprynet.com
AP_BATCHES_ALL

• All Invoice batch information is stored here


– Batch Name
– Batch Date
– Control and Actual Totals
– Payment Currency
– Org_ID

OASIS
Consulting Group, Inc.
Steve Bradley sbradley@sprynet.com
AP_INVOICES_ALL

• All invoice header information is stored


here
– Vendor ID
– Vendor Site ID
– Invoice Number
– Invoice Amount
– Invoice Date
– Currency
– Terms Code
OASIS
Consulting Group, Inc.
Steve Bradley sbradley@sprynet.com
AP_INVOICE_DISTRIBUTIONS_ALL

• All AFF distribution information is stored


here
– One record for every distribution line of an
invoice
• Distribution amount
• CCID
• 1099 Info
• PO Match Info

OASIS
Consulting Group, Inc.
Steve Bradley sbradley@sprynet.com
AP_CHECKS_ALL

• All Check information


– Bank Account ID
– Check Date
– Check Number
– Address on Check
– Vendor Name
– Cleared Info

OASIS
Consulting Group, Inc.
Steve Bradley sbradley@sprynet.com
Table Relationships
• Oracle is a “Relational Database”
– All data is not stored in one table
– Data is not duplicated in different tables
– You must use table relationships to “join”
tables to see the full picture

OASIS
Consulting Group, Inc.
Steve Bradley sbradley@sprynet.com
Relationship Example
• Vendor names are not stored in the
AP_INVOICES_ALL table
They are stored in the PO_VENDORS table
• AP_INVOICES_ALL has a column named
vendor_id
• PO_VENDORS also has a column named
vendor_id

OASIS
Consulting Group, Inc.
Steve Bradley sbradley@sprynet.com
Table Relationships

Vendor_ID
PO_Vendors AP_Invoices_All
Vendor_ID Vendor_ID

Where PO_Vendors.Vendor_id =
AP_Invoices_All.Vendor_id

OASIS
Consulting Group, Inc.
Steve Bradley sbradley@sprynet.com
Table Relationships

Vendor_ID AP_Invoices_All
PO_Vendors Vendor_ID
Vendor_ID Vendor_Site_ID
Invoice_ID

Vendor_ID Vendor_Site_ID Invoice_ID

PO_Vendor_Sites_All
AP_Invoice_Dist_All
Vendor_ID
Invoice_ID
Vendor_Site_ID

OASIS
Consulting Group, Inc.
Steve Bradley sbradley@sprynet.com
Unused Vendors
• During initial Oracle Payables
implementation typically all vendors in the
old system are copied over to Oracle.
• Many of these vendors are never used in
Oracle.
• How can you get a list of them?

OASIS
Consulting Group, Inc.
Steve Bradley sbradley@sprynet.com
--Vendors with no Invoices
select segment1 VENDOR#,
vendor_name NAME,
vendor_site_code SITE_CODE,
end_date_active VEND_INACTIVE,
inactive_date SITE_INACTIVE
from po_vendors vend,
po_vendor_sites_all sites,
ap_invoices_all inv
where vend.vendor_id = sites.vendor_id
and sites.vendor_site_id = inv.vendor_site_id(+)
and inv.vendor_site_id is null;

OASIS
Consulting Group, Inc.
Consulting Group, Inc.
Legal Disclaimer
• Oracle does not provide Application support for
non-interface tables that have been updated
directly using SQL
• Use these SQL scripts at your own risk
• You can give me credit for these scripts but I will
accept no blame for their use
• Do not call me with problems or support
• If you do not understand them - do not use them

OASIS
Consulting Group, Inc.
Steve Bradley sbradley@sprynet.com
Practical Examples
• Vendor Merge
– Fix Duplicate Invoices resulting from a merge
– Duplicate Vendors Listing
– Vendor Unmerge
• Delete Unused Vendor Sites

OASIS
Consulting Group, Inc.
Steve Bradley sbradley@sprynet.com
Practical Examples
• Dead Vendors
– Unused Vendors
– Vendors with only activity being
Canceled Invoices
– Vendors with % in name

OASIS
Consulting Group, Inc.
Steve Bradley sbradley@sprynet.com
T.O.A.D
• Tool for Oracle Application Developers
• Great tool for writing SQL
• It’s free - download from:
www.toadsoft.com
• Must download new version every 2 months

OASIS
Consulting Group, Inc.
Steve Bradley sbradley@sprynet.com
T.O.A.D Features
• Easy editing features - cut and paste, query recall
• Output goes to a grid - does not wrap like Oracle
• You can change the order of the output columns
after running
• Can export data in .CSV format (can then import
into Excel)
• Can save SQL scripts to PC and use later

OASIS
Consulting Group, Inc.
Steve Bradley sbradley@sprynet.com
OASIS
Consulting Group, Inc.
Steve Bradley sbradley@sprynet.com
OASIS
Consulting Group, Inc.
Steve Bradley sbradley@sprynet.com
OASIS
Consulting Group, Inc.
Steve Bradley sbradley@sprynet.com
Questions

Steve Bradley
OASIS Consulting Group
sbradley@sprynet.com
Office 404-352-8387
FAX 503-218-9747
Pager 888-912-2569

OASIS
Consulting Group, Inc.
Steve Bradley sbradley@sprynet.com

You might also like