fhg
Volume 7, Number 22 -- June 13, 2007

Joining on Mismatched Values

Published: June 13, 2007

Hey, Ted:

Like many shops, we have a mixture of database files that we have acquired from different sources due to mergers and acquisitions over the years. Getting things to match up is challenging, to put it mildly. I have two files that contain warehouse code fields, but the codes do not match exactly. In one file, a certain warehouse is indicated by the letter T. In the other file, the same warehouse is the character 1 (one). All other warehouses have the same codes in both files.

I need to join these files, but I don't know what to do about the warehouse with different codes. I thought of setting up a cross-reference file, but wondered if there is any way to avoid it. A cross-reference file would be yet another file to maintain when we add new warehouses. Is there a way to tell SQL that T in one file matches 1 in the other file?

--CS


My gut feeling is that the warehouse cross-reference file is probably your best way to go, unless you have only one program that needs to carry out such a join. Anyway, you'll have to be the judge of that.

If you want to avoid the cross reference, use a CASE statement in your join. Here's an example that uses two files, XACT and MASTER. Warehouse T in XACT is warehouse 1 in MASTER.

SELECT xact.KEY, xact.whs, mast.WhsID, mast.WhsName 
  FROM xact AS xact 
  LEFT JOIN master AS mast 
    ON CASE 
         WHEN xact.whs = 'T' 
           THEN '1' 
           ELSE xact.whs 
        END = mast.WhsID

The CASE converts T to 1, but leaves other warehouse codes as they are. The value from the CASE is compared to the WhsID field in the MASTER file.

--Ted



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


Sponsored By
VISION SOLUTIONS


HA for $50/day?


You bet!


If you think HA is too expensive,
think again.


Learn more at


www.visionsolutions.com/50.aspx



Senior Technical Editor: Ted Holt
Technical Editors: Howard Arner, Joe Hertvik, Shannon O'Donnell, Kevin Vandever
Contributing Technical Editors: Joel Cochran, Wayne O. Evans, Raymond Everhart,
Bruce Guetzkow, Brian Kelly, Marc Logemann, David Morris
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

Midrange Alliance:  Free Gartner Whitepaper on massive iSeries modernization project
Help/Systems:  SEQUEL is the single solution for all your business intelligence needs
COMMON:  Join us at the Annual 2008 conference, March 30 - April 3, in Nashville, Tennessee


IT Jungle Store Top Book Picks

The System i Pocket RPG & RPG IV Guide: List Price, $69.95
The iSeries Pocket Database Guide: List Price, $59.00
The iSeries Pocket Developers' 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
iSeries Express Web Implementer's Guide: List Price, $59.00
Getting Started with WebSphere Development Studio for iSeries: List Price, $79.95
Getting Started With WebSphere Development Studio Client for iSeries: List Price, $89.00
Getting Started with WebSphere Express for iSeries: List Price, $49.00
WebFacing Application Design and Development Guide: List Price, $55.00
Can the AS/400 Survive IBM?: List Price, $49.00
The All-Everything Machine: List Price, $29.95
Chip Wars: List Price, $29.95

 

The Four Hundred
The i5 515 and 525 Versus the Windows Competition

CIOs Get Ready to Hire in the Summer

One More Time: There Is No Gender Pay Gap

As I See It: The Ne'er-Do-Well's Guide to Enlightenment

The Linux Beacon
Sun Broadens Its Blade Server Lineup

CIOs Get Ready to Hire in the Summer

Open Source Software Sales Pegged at $5.8 Billion by 2011

Mad Dog 21/21: Missing Inaction

Four Hundred Stuff
ASNA Preps AVR for Visual Studio 2008

Interpro Dots the 'i' for Application Translations

RPG Pro Rescues Project with WebSmart and Web Services

Boomi Goes 'On Demand' with Integration Software

Big Iron
The Pizza Disconnection

Top Mainframe Stories From Around the Web

Chats, Webinars, Seminars, Shows, and Other Happenings

System i PTF Guide
June 9, 2007: Volume 9, Number 23

June 2, 2007: Volume 9, Number 22

May 26, 2007: Volume 9, Number 21

May 19, 2007: Volume 9, Number 20

May 12, 2007: Volume 9, Number 19

May 5, 2007: Volume 9, Number 18

The Windows Observer
Muglia Lifts the Covers on Upcoming Products at Tech Ed

Microsoft Unveils 'Stirling' Security Suite

Xandros Inks Patent Protection, Interoperability Deal with Microsoft, Too

Microsoft Adds Goodies to Vista Enterprise Kit

The Unix Guardian
Project Indiana to Create an OpenSolaris Distro

Sun Broadens Its Blade Server Lineup

HP Tweaks Home-Grown Virtualization for Integrity Servers

Mad Dog 21/21: Missing Inaction

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

THIS ISSUE SPONSORED BY:

Midrange Alliance
Vision Solutions
WorksRight Software



TABLE OF CONTENTS
Fix Decimal Data Errors

Joining on Mismatched Values

Admin Alert: Alternative Ways to Print PC5250 Screens

Four Hundred Guru

BACK ISSUES

From the IT Jungle Forums
Keeping a trace of each CL

Problem with "cpyfrmimpf"

FTP a library to a server

Uploading data from Excel to the iSeries

How to calculate the last day of the month





 
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-2008 Guild Companies, Inc. All Rights Reserved.
Guild Companies, Inc., 50 Park Terrace East, Suite 8F, New York, NY 10034

Privacy Statement