fhg
Volume 9, Number 32 -- October 14, 2009

How Do I Find What's Not There?

Published: October 14, 2009

Hey, Ted:

Our inventory items are assigned seven-digit numbers. When we accept an order for a custom product, we assign it a number, build the product, ship it, and retire the number. After a few years, the system automatically purges these numbers, which means we are free to reuse these numbers. Is there a way to make an SQL query find the numbers within a range that are not assigned to items?

--Tim


I'll give you a method that works at V5R4 or above, Tim.

Let's say your database file is IBM's famous QIWS/QCUSTCDT, and that you want to find available customer numbers in the range 938470 through 938479. There is only one customer in that range--G. K. Henning, who has been assigned the number 938472--so we should get a list of nine available numbers.

Here's the query.

with list (Number) as
(select 938470
   from qsys2/qsqptabl
  union all
 select Number+1
   from list
  where Number < 938479)
select Number from list
  where Number not in
       (select cusnum
          from qiws/qcustcdt)
order by 1

Now let's tear this apart.

The recursive common table expression, list, builds a temporary table of all the whole numbers in the range 938470 through 938479.

Following the common table expression, the main select retrieves all numbers in list that are not found as customer numbers in QCUSTCDT.

Voilą!

--Ted




                     Post this story to del.icio.us
               Post this story to Digg
    Post this story to Slashdot


Sponsored By
PROFOUND LOGIC SOFTWARE

Successful companies use RPGsp for
Web Application Development

Western Power Sports boosted online sales
five-fold by modernizing with RPGsp.

Learn why they are saying "It's the best all around solution for the IBM i"
and "no other product compares."

Western Power Supports runs six websites using Profound Logic's RPGsp.
WPS reports $250,000 in online sales every day since transferring to the new site,
an impressive 500% increase.

Click here to view the Western Power Sports' story
and download the complete case study.


Senior Technical Editor: Ted Holt
Technical Editor: Joe Hertvik
Contributing Technical Editors: Erwin Earley, Brian Kelly, Michael Sansoterra
Publisher and Advertising Director: Jenny Thomas
Advertising Sales Representative: Kim Reed
Contact the Editors: To contact anyone on the IT Jungle Team
Go to our contacts page and send us a message.

Sponsored Links

Vision Solutions:  Free software for measuring overall i5/OS system health
Manta Technologies:  Fall Sale on i training courses! Order by October 15 and SAVE 25%
S4i Systems:  Express manages System i, mainframe, and any LINUX, UNIX, AIX document files


 

IT Jungle Store Top Book Picks

Easy Steps to Internet Programming for AS/400, iSeries, and System i: List Price, $49.95
The iSeries Express Web Implementer's Guide: List Price, $49.95
The System i RPG & RPG IV Tutorial and Lab Exercises: List Price, $59.95
The System i Pocket RPG & RPG IV Guide: List Price, $69.95
The iSeries Pocket Database Guide: List Price, $59.00
The iSeries Pocket SQL Guide: List Price, $59.00
The iSeries Pocket Query Guide: List Price, $49.00
The iSeries Pocket WebFacing Primer: List Price, $39.00
Migrating to WebSphere Express for iSeries: List Price, $49.00
Getting Started With WebSphere Development Studio Client for iSeries: List Price, $89.00
Getting Started with WebSphere Express for iSeries: List Price, $49.00
Can the AS/400 Survive IBM?: List Price, $49.00
Chip Wars: List Price, $29.95


 
The Four Hundred
IBM's DB2 Pure Scale--Not Quite iDatabase V1

Early Views on iManifest: ISV Expectations, Public Misconceptions

News Flash: IT to Drive Economic Recovery

As I See It: The Greening of IT

The Power Systems Catalog Gets Skinnier

Four Hundred Stuff
Cloud Storage Services Make their Way to the i OS Midrange

MKS Adds Test Management to ALM Suite

Gartner Ranks the Managed File Transfer Products

Vision Analyzes i OS Server Health with Free iSCORE Tool

LANSA Integrates with Oracle for Supply Chain Interoperability

Four Hundred Monitor
Four Hundred Monitor's
Full iSeries Events Calendar

System i PTF Guide
October 10, 2009: Volume 11, Number 41

October 3, 2009: Volume 11, Number 40

September 26, 2009: Volume 11, Number 39

September 19, 2009: Volume 11, Number 38

September 12, 2009: Volume 11, Number 37

September 5, 2009: Volume 11, Number 36

August 29, 2009: Volume 11, Number 35

TPM at The Register
Ellison whips out his Sparc TPC-C test

HP, EMC cozy up to Oracle

Sun kicks out 10/09 Solaris update

Google: Servers are DIMM witted

Cisco rewards bit twiddlers in router-to-server contest

Alpha-male Ellison issues $10m Exadata challenge

Cisco readies rack servers for the holidays

IBM throws DB2 Power cluster at Ellison's Exadata

EMC outs Atmos compute cloud

Sun adds Oracle Linux to ops tools

Parallels bares all with server hypervisor

Terracotta straps on Ehcache speed engine

THIS ISSUE SPONSORED BY:

Help/Systems
Profound Logic Software
Manta Technologies


Printer Friendly Version


TABLE OF CONTENTS
Getting the Message, Part 1

How Do I Find What's Not There?

Admin Alert: Locking Down i5/OS System Security Values

Four Hundred Guru

BACK ISSUES




 
Subscription Information:
You can unsubscribe, change your email address, or sign up for any of IT Jungle's free e-newsletters through our Web site at http://www.itjungle.com/sub/subscribe.html.

Copyright © 1996-2009 Guild Companies, Inc. All Rights Reserved.
Guild Companies, Inc., 50 Park Terrace East, Suite 8F, New York, NY 10034

Privacy Statement