References & SQL Tips



Similar documents
Advanced SQL. Jim Mason. Web solutions for iseries engineer, build, deploy, support, train

Intro to Embedded SQL Programming for ILE RPG Developers

2 SQL in iseries Navigator

Oracle Database: SQL and PL/SQL Fundamentals NEW

Oracle Database: SQL and PL/SQL Fundamentals

IBM i Version 7.2. Database Distributed database programming

Maintaining Stored Procedures in Database Application

SQL Basics for RPG Developers

Instant SQL Programming

Using SQL in RPG Programs: An Introduction

Oracle Database 12c: Introduction to SQL Ed 1.1

SQL. Agenda. Where you want to go Today for database access. What is SQL

Migrate AS 400 Applications to Linux

4 Simple Database Features

ERserver. iseries. DB2 Universal Database for iseries - Database Performance and Query Optimization

Oracle Database: SQL and PL/SQL Fundamentals

Chapter 9, More SQL: Assertions, Views, and Programming Techniques

1 Structured Query Language: Again. 2 Joining Tables

ERserver. DB2 Universal Database for iseries SQL Programming with Host Languages. iseries. Version 5

Migrate AS 400 Applications to Windows, UNIX or Linux

SQL Server for developers. murach's TRAINING & REFERENCE. Bryan Syverson. Mike Murach & Associates, Inc. Joel Murach

Oracle SQL. Course Summary. Duration. Objectives

SQL Server. 1. What is RDBMS?

MOC 20461C: Querying Microsoft SQL Server. Course Overview

Oracle Database 11g SQL

Oracle 10g PL/SQL Training

Duration Vendor Audience 5 Days Oracle End Users, Developers, Technical Consultants and Support Staff

DBMS / Business Intelligence, SQL Server

Chapter 9 Joining Data from Multiple Tables. Oracle 10g: SQL

Revolutionized DB2 Test Data Management

Tips and techniques to improve DB2 Web Query for i performance and productivity

Oracle Database: SQL and PL/SQL Fundamentals NEW

Migrating Non-Oracle Databases and their Applications to Oracle Database 12c O R A C L E W H I T E P A P E R D E C E M B E R

Fast Query Manuale Sistemista. Fast Query System users guide

iseries SQL Programming: You ve Got the Power!

You re probably already familiar with using a File Transfer Protocol (FTP)

DB2 for i5/os: Tuning for Performance

Oracle Database 10g: Introduction to SQL

Embedding SQL in High Level Language Programs

User Guide Flying Cloud Drive, Suite 200 Eden Prairie, MN Phone 952/ Fax 952/

Advantages of PML as an iseries Web Development Language

SQL Server 2008 Core Skills. Gary Young 2011

Advanced Query for Query Developers

Presentation for The Omni User Group By Bob Dunn and Doug Bridwell

Workflow Templates Library

Introducing Microsoft SQL Server 2012 Getting Started with SQL Server Management Studio

PL/SQL MOCK TEST PL/SQL MOCK TEST I

PeopleSoft DDL & DDL Management

Querying Microsoft SQL Server

IBM Power Systems Software. The ABCs of Coding High Performance SQL Apps DB2 for IBM i. Presented by Jarek Miszczyk IBM Rochester, ISV Enablement

Oracle8/ SQLJ Programming

ERserver. iseries. Work management

A basic create statement for a simple student table would look like the following.

Embarcadero DB Change Manager

Meeting Users' Needs with Free Software for your IBM i

Microsoft Access Basics

In the March article, RPG Web

Introduction to Databases

Accesssing External Databases From ILE RPG (with help from Java)

Oracle Database: Introduction to SQL

Relational Databases for the Business Analyst

JD Edwards World. Database Audit Manager Release A9.3 E

Querying Microsoft SQL Server 2012

Teamstudio USER GUIDE

Top 10 Considerations for Selecting the Right RMM Solution

D61830GC30. MySQL for Developers. Summary. Introduction. Prerequisites. At Course completion After completing this course, students will be able to:

Oracle Database: Introduction to SQL

Course ID#: W 35 Hrs. Course Content

The release notes provide details of enhancements and features in Cloudera ODBC Driver for Impala , as well as the version history.

Course 10774A: Querying Microsoft SQL Server 2012

Course 10774A: Querying Microsoft SQL Server 2012 Length: 5 Days Published: May 25, 2012 Language(s): English Audience(s): IT Professionals

An Oracle White Paper June Migrating Applications and Databases with Oracle Database 12c

TechTips. Connecting Xcelsius Dashboards to External Data Sources using: Web Services (Dynamic Web Query)

Native AS/400 - iseries Report Converters

Advanced Tornado TWENTYONE Advanced Tornado Accessing MySQL from Python LAB

Session: Archiving DB2 comes to the rescue (twice) Steve Thomas CA Technologies. Tuesday Nov 18th 10:00 Platform: z/os

Developing Web Applications for Microsoft SQL Server Databases - What you need to know

Data Mining Commonly Used SQL Statements

Web Intelligence User Guide

dbext for Vim David Fishburn h5p://

SQL. by Steven Holzner, Ph.D. ALPHA. A member of Penguin Group (USA) Inc.

COMMON All Day Lab 10/16/2007 Hands on VB.net and ASP.Net for iseries Developers

Querying Microsoft SQL Server Course M Day(s) 30:00 Hours

Microsoft Office Access 2007 which I refer to as Access throughout this book

Carol President and Co-Founder SkyView Partners, Inc

Data Tool Platform SQL Development Tools

Facebook Twitter YouTube Google Plus Website

HP Quality Center. Upgrade Preparation Guide

Database Management System Choices. Introduction To Database Systems CSE 373 Spring 2013

Cal Answers Analysis Training Part I. Creating Analyses in OBIEE

CHAPTER 1: CLIENT/SERVER INTEGRATED DEVELOPMENT ENVIRONMENT (C/SIDE)

MyOra 3.0. User Guide. SQL Tool for Oracle. Jayam Systems, LLC

Lerox DB/2 Database Dictionary in QlikView for IBM System AS/400, iseries i5, System i

ComCon. Extract From Embedded SQL in RPG. Paul Tuohy

Structured Query Language (SQL)

Zend Framework Database Access

Transcription:

References & SQL Tips Speaker: David Larsen (dlarsen@lagoonpark.com), Software Engineer at Lagoon Corporation Topic: SQL Tips and Techniques on the IBM i Date: Wednesday, January 14th, 2015 Time: 11:00 a.m. 12:00 noon Location: Murray City Offices (City Council Chambers), 5025 South State Street, Murray, Utah. Modernizing IBM i Applications from the Database up to the User Interface and Everything in Between sg248185.pdf Read and Study Chapters 8 and 9. RCAC for DB2 for i http://www.redbooks.ibm.com/redpieces/pdfs/redp5110.pdf IBM i Version 7.2 Database DB2 for i SQL Reference - 1,596 pages http://www-01.ibm.com/support/knowledgecenter/api/content/ssw_ibm_i_72/db2/rbafzpdf.pdf IBM i Version 7.2 Database SQL programming http://www-01.ibm.com/support/knowledgecenter/api/content/ssw_ibm_i_72/sqlp/rbafypdf.pdf http://iprodeveloper.com/database/teach-your-old-db2-new-tricks http://iprodeveloper.com/sql/simplify-dds-sql-conversion Replacing a DDS Physical File with an SQL Table http://iprodeveloper.com/database/replacing-dds-physical-file-sql-table Database Harmony: "Traditional" and SQL Coexistence http://iprodeveloper.com/rpg-programming/database-harmony-traditional-and-sql-coexistence More SQL and dates part I http://www.rpgpgm.com/2013/09/more-sql-and-dates-part-i.html http://www.rpgpgm.com/2013/09/more-sql-and-dates-part-ii.html http://www.rpgpgm.com/2014/09/ftp-i-to-i-part-3.html Using Date Tools for SQL and Excel http://iprodeveloper.com/database/using-date-tools-sql-and-excel Get Your SQL Surge On http://event.on24.com/eventregistration/eventlobbyservlet?target=lobby.jsp&eventid=835928&sessionid=1&partnerr ef=thankyous&key=6aa27a32af883cfe9d34923719f7148f&eventuserid=103379436

Procedures, and Functions, and Catalogs! Oh My! http://www.mcpressonline.com/programming/sql/procedures-and-functions-and-catalogs-oh-my.html In 7.1 SQLRPGLE Can Read Stored Procedure Result Sets From <http://iprodeveloper.com/sql/71-sqlrpgle-can-read-stored-procedure-result-sets> IBM DB2 for i Advanced SQL Programming - IBM Training From <http://www.youtube.com/watch?v=abzzxmrxvgy> Coding SQL Routines on the Fast Track From <http://iprodeveloper.com/database/coding-sql-routines-fast-track> SQL's Other Fetch Options From <http://www.itjungle.com/fhg/fhg051309-story02.html> Good stuff! Set eof or bof. Sequential and random reads Creating a SQL table "on the fly" From <http://www.rpgpgm.com/2014/01/creating-sql-table-on-fly.html> Resetting the identity column in a SQL table http://www.rpgpgm.com/2014/06/resetting-identity-column-in-sql-table.html Complex Joins in SQL http://www.toadworld.com/platforms/ibmdb2/w/wiki/7755.complex-sql-guidelines.aspx Embedding SQL in RPG IV--Episode II http://www.itjungle.com/fhg/fhg082405-story01.html SQL Functions Extend RPG http://iprodeveloper.com/rpg-programming/sql-functions-extend-rpg COMPARE TWO TABLES and get only unmatched records To compare all the columns/rows in TABLE1 to those in TABLE2 you can use the EXCEPT function as follows: SELECT * FROM TABLE1 EXCEPT SELECT * FROM TABLE2; The above SQL will display all rows from TABLE1 that don t match or exist on TABLE2. The number of columns being compared and their data type have to match and you can t compare certain column types (such as CLOB/BLOB/XML). The nice thing about this, is the EXCEPT function takes care of all the comparison details for you unlike when trying to use the WHERE NOT EXISTS clause. From <http://jmerrell.com/2011/06/01/db2-except-sql-function/> Create Database Files from SQL Queries From <http://www.itjungle.com/fhg/fhg111506-story01.html> REPLACE to Replace Characters in a String From <http://www.itjungle.com/fhg/fhg072711-story01.html> SELECT name, company, REPLACE(phone, '-', '') AS phone FROM namemstr Create or Replace a File

http://iprodeveloper.com/database/use-sql-create-or-replace-improve-db2-i-object-management A Match Made in SQL From <http://iprodeveloper.com/sql/match-made-sql> Embedding SQL in RPGLE http://www.penton.com/webcasts/day2session3-introtoembeddedsql_cruikshank.pdf How to use DB2's cross-reference files to help http://search400.techtarget.com/tip/how-to-use-db2s-cross-reference-files-to-help-manage-your-database-part-i> SQL Arrays in DB2 for i 7.1 http://ibmsystemsmag.com/ibmi/administrator/db2/sql-arrays-in-db2-for-i-7-1/ Free Format SQLRPGLE Shell Program 1 Author: Lionel Halvorsen http://www.ilerpgprogramming.com/2010/02/free-format-sqlrpgle-shell-program-1.html Free Format SQLRPGLE Shell Program: part 2 Author: Lionel Halvorsen Feb 26, 2010 <http://www.ilerpgprogramming.com/2010/02/free-format-sqlrpgle-shell-program-part.html> Free Format SQLRPGLE Shell Program: part 3 Author: Lionel Halvorsen Mar 1, 2010 From <http://www.ilerpgprogramming.com/2010/03/free-format-sqlrpgle-shell-program-part.html> Comparing SQL DDL with DDS for creating files. From <http://www.ilerpgprogramming.com/2009/05/comparing-sql-ddl-with-dds-for-creating.html> SQL in free format RPG Do you use SQL and free format RPG independently but haven't really put the two together yet? If so then this article is for you. Executing SQL statements in free format RPG may be a lot easier than you think. Doing so can streamline and speed up your legacy code. From <http://www.ilerpgprogramming.com/2009/04/sql-in-free-format-rpg.html> Run SQL statements automatically with RUNSQLSTM STRSQL is a powerful and useful interactive tool (in the right hands) but it can be cumbersome to retrieve previous SQL statements, modify them and then run them again all the while hoping there are no typos. If you find yourself frequently entering the same SQL commands why not save them to a text file and automate the process? I like to save the SQL statements in a source file named qtxtsrc. Once saved the SQL can be executed from a CL containing the RUNSQLSTM command. In this example two inventory file field definitions were reversed during an upgrade and the data had to be swapped (mapped correctly) during the process. This can be accomplished with one SQL statement. Note that there is no need for messy work fields that might otherwise be used when coding the same solution in RPG. Step 1. Create the text type source member. Contents of the source member sqlfswap (saved as a text file): update datalib/invenpf set field1 = field2, field2 = field1

Step 2. Create CL member sqlfswapcl: ADDLIBLE mylib MONMSG msgid(cpf0000) RUNSQLSTM srcfile(mylib/qtxtsrc) srcmbr(sqlfswap) MONMSG msgid(cpf0000) endpgm Step 3. Run the CL and check your results. Of course the CL can be set up on the job scheduler (wrkjobscde) if your application needs to be run automatically at specified intervals and multiple sql statements can be added into the same text source member. From <http://www.ilerpgprogramming.com/2009/02/run-sql-statements-automatically-with.html> Yet another reason why to work with real date and time values: SQL provides a lot of scalar functions for date and time calculation that can be easily used in RPG. Example: /Free Exec SQL Set :MyWeekIso = Week_ISO(:MyDate); Dsply MyWeekIso; Exec SQL Set :MyMonthEnd = Last_Day(:MyDate); Exec SQL Set :NextMonday = Next_Day(:MyDate, 'Monday'); Exec SQL Set :IsWeekEnd = Case When DayOfWeek_ISO >= 6 Then '1' Else '0' End; /End-Free Those functions only work with real date/time fields. SQL does not play very nicely with numeric date/time fields. From <http://ibmsystemsmag.blogs.com/idevelop/2014/07/rpg-speed-dating-.html> iprodeveloper PowerPack Turbocharge IBM i with SQL. http://iprodeveloper.com/power-packs/turbocharge-ibm-i-sql-power-pack Simplify DDS to SQL Conversion TR7 adds support for keyed file objects to the Generate SQL utility http://iprodeveloper.com/sql/simplify-dds-sql-conversion Achieve improved database interoperability with SQL and RDB aliases http://www.ibm.com/developerworks/ibmi/library/i-improved-database-interoperability-sql- rdb/index.html?ca=drs- Selected common SQL features for developers of portable DB2 applications http://www.ibm.com/developerworks/data/library/techarticle/db2common/previouslevel3.html?ca=drs- TechTip: Direct SQL Control of System Names http://www.mcpressonline.com/sql/techtip-direct-sql-control-of-system-names.html Coding SQL statements in ILE RPG applications http://www-01.ibm.com/support/knowledgecenter/api/content/ssw_ibm_i_71/rzajp/rzajprpgi.htm You can generate the SQL to create a collection (library) and all physical and logical indexes in the selected library needed with System I Navigator. Take the option to create the output to a source file member. Then use RUNSQLSTM to execute the statements from that member to create your new collection. ATTENTION: You will need to put the correct right margin length on RUNSQLSTM or it will not work (EG default = MARGINS(80); otherwise = MARGINS(100)

Cast Your Data Conversion Troubles Away If you have different CCSIDs for tables or columns on your system http://www.itjungle.com/mpo/mpo091103-story03.html SQL Functions You Didn't Know You Had, Part 1 http://www.itjungle.com/fhg/fhg102214-story01.html SQL Functions You Didn't Know You Had, Part 2 http://www.itjungle.com/fhg/fhg111214-story02.html> IBM I Links you will need http://ibmsystemsmag.com/blogs/you-and-i/december-2014/ibm-i-links-you-need/?utm_campaign=ibmenews&utm_medium=email&utm_source=ibmi-jan14-2015-newver&utm_content=blog-youandi-title Paging Cursors http://www.itjungle.com/fhg/fhg102214-story02.html SQL UNION to get subtotals http://search400.techtarget.com/tip/sql-union-to-get-subtotals SELECT Company, Region, District, ' ', COUNT(*) FROM StoreTbl GROUP BY Company, Region, District UNION SELECT Company, Region, 999, 'Region ' DIGITS(Region), COUNT(*) FROM StoreTbl GROUP BY Company, Region UNION SELECT Company, 999 999, 'Company' Company, count(*) from StoreTbl group by Company order by Company IBM DB2 for i: Tips Frequently asked questions: Improving performance with SQL packages http://www-03.ibm.com/systems/power/software/i/db2/support/tips/sqlperffaq.html#header_1 A Concise Guide to SQL Triggers http://iprodeveloper.com/database/concise-guide-sql-triggers

Education www.w3schools.com www.udemy.com www.php.net www.edx.com www.codeacademy.com www.youtube.com References Database Embedded Programming http://www-01.ibm.com/support/knowledgecenter/api/content/nl/en-us/ssw_ibm_i_72/rzajp/rzajppdf.pdf DDS and SQL - The Winning Combination for DB2 for i: White Paper Download Link http://www-304.ibm.com/partnerworld/wps/servlet/contenthandler/whitepaper/ibmi/db2/sql IBM i Database SQL Programming 7.1 rbafy http://www-01.ibm.com/support/knowledgecenter/api/content/nl/en-us/ssw_ibm_i_71/sqlp/rbafy.pdf DB2 for I SQL Reference Manual http://www-01.ibm.com/support/knowledgecenter/ssw_ibm_i_72/db2/rbafzpdf.pdf?lang=en-us Improving SQL procedure performance by Kent Milligan http://www- 304.ibm.com/partnerworld/wps/servlet/ContentHandler/whitepaper/ibmi/sql_sql_v6r1/procedure Moving From OPNQRYF to SQL http://www- 304.ibm.com/partnerworld/wps/servlet/ContentHandler/whitepaper/i5os/OPNQRYF_SQL/move?pageI d=pw.sellingresources Stored Procedures, Triggers, and User-Defined Functions on DB2 Universal Database for iseries http://www.redbooks.ibm.com/redbooks.nsf/redbookabstracts/sg246503.html?open Using SQL views and stored procedures with DB2 Web Query http://www-304.ibm.com/partnerworld/wps/servlet/contenthandler/whitepaper/i5os/db2_sql/security