Home > Ask the AS/400 Experts > DB2/400 and DB2 UDB Questions & Answers > Selecting a PF with multiple members from SQL
Ask The iSeries 400 Expert: Questions & Answers
EMAIL THIS

Selecting a PF with multiple members from SQL

Kent Milligan EXPERT RESPONSE FROM: Kent Milligan

Pose a Question
Other iSeries 400 Categories
Meet all iSeries 400 Experts
Become an Expert for this site


iSeries news and advice
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


>
QUESTION POSED ON: 04 July 2008
How can I select a physical file (PF) with multiple members on AS/400 from Windows SQL?


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google



RELATED CONTENT
DB2/400 and DB2 UDB
When is the YES option for 'reuse deleted files' function the best choice?
Monitoring members 'stuck' within a physical file on an EDI system
Developing tables in a parent-child relationship in DB2
SQL server error message -321
Creating a host variable of the 'where in' statement in SQL
Choose which column names are returned via ODBC when working with DB2 files
Allow access to data from a stored procedure result set using COBOL or RPG
Access path and an open data path differences
Convert a numeric physical file to a character in SQL without leading zeros
Inserting data from a CTE into a file in SQL

iSeries SQL commands and statements
Enhancing RPG with external SQL stored procedures
Tracking data changes on IBM i with triggers
Introduction to SQLRPGLE on IBM i: Making a report
Making the most of RPG data handling on IBM i
When is the YES option for 'reuse deleted files' function the best choice?
Monitoring members 'stuck' within a physical file on an EDI system
Creating a host variable of the 'where in' statement in SQL
SQL server error message -321
Choose which column names are returned via ODBC when working with DB2 files
Convert a numeric physical file to a character in SQL without leading zeros
iSeries SQL commands and statements Research

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary


The simplest technique is to create an alias using SQL for each member that you want to access with SQL. Here's an example of creating aliases.
CREATE DBLIB/AM1 FOR DBLIB/FILE(M1)
CREATE DBLIB/AM2 FOR DBLIB/FILE(M2)

Once the SQL ALIAS is created, any SQL interface can reference the alias name just like a table name.

The SQL alias object requires no maintenance, so creating the aliases should be a one-time operation. There's no overhead leaving the alias objects around.

Editor's note: We received a follow-up question to this question and answer:

First: The right statement is:
Create ALIAS DBLIB/AM1 FOR DBLIB/FILE(M1)

Second: You wrote, "Once the SQL ALIAS is created, any SQL interface can reference the alias name just like a table name." But if I have to use information from this member with information from other files, normaly I use: Create view myView as... That is not possible with alias. Is there another way to use a member in a view?

Kent responded with this:

You are correct, I did omit the alias keyword from my example. And an alias object cannot be referenced in a view definition.

One way to encapsulate an alias reference and then embed into a view definition is create a user-defined table function (UDTF):

CREATE FUNCTION aliasudtf() 

RETURNS  TABLE(col2 char(6), col3  int) 
LANGUAGE SQL 
NO EXTERNAL ACTION 
DETERMINISTIC 
DISALLOW PARALLEL 
BEGIN 
Return ( 
select c2,c3 from alias1 
 union all 
select c2,c3 from alias2); 
END; 

Here's an example of how to reference a UDTF on a SELECT statement. UDTF references are allowed when creating views:

   SELECT col2 FROM TABLE( aliasudtf() )  x; 




Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice



iSeries Networking - Printing, Remote Access, TCP/IP
HomeNewsTopicsITKnowledge ExchangeTipsBlogsAsk the ExpertsMultimediaWhite PapersProducts
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts