Friday, May 24, 2013

SQL select statement from specific member of AS400 file

In some cases, you might want to select data from a file that contains multiple members, but only the data from one of the members.  Here is the instructions on how to do so.

First, we need to create an alias to define the member to the query.

CREATE ALIAS ALIAS1 FOR FILE1(MEMBER1)

Now that the alias has been created, it is pointing to that member of the file.  We can select from it as normal.

SELECT * FROM ALIAS1 WHERE FIELD1='ABC123'

This select statement selects the records from member MEMBER1 in file FILE1 when the FIELD1 field contains the value "ABC123".

Don't forget to run the following statement when you are finished.  Otherwise, someone else could accidentally use your alias from another session!

DROP ALIAS ALIAS1

No comments:

Post a Comment