Problem solve Get help with specific problems with your technologies, process and projects.

Set SQL outfile column names

Here you'll learn how you can control the column names used when creating an outfile from SQL.

You can control the column names used when creating an outfile from SQL. This is especially useful when you have the same source column from 2 different files, fields with long alias names, or when the output contains calculations.

Example 1:

 
RUNSQL REQUEST('SELECT T1.MBFILE, T1.MBNRCD, T2.MBNRCD, T1.MBNRCD - T2.MBNRCD  
 FROM QTEMP/DSPFD_PROD T1, QTEMP/DSPFD_TRAN T2 WHERE T1.MBFILE = T2.MBFILE AND 
 T1.MBNRCD <> T2.MBNRCD') OUTPUT(*OUTFILE) OUTFILE(QTEMP/DSPFD_DIFF)    

This will create a table with the below named columns:

 
MBFILE         10   
MBNRCD         10,0 
MBNRCD1        10,0 
SEL2           11,0 

You can specify what you want to name the output columns, by following the field name with a double-quoted value.

Example 2:

RUNSQL REQUEST('SELECT T1.MBFILE, T1.MBNRCD "PROD_NRCD", T2.MBNRCD "TRAN_NRCD", 
T1.MBNRCD - T2.MBNRCD "DIFF_NRCD" FROM QTEMP/DSPFD_PROD T1, QTEMP/DSPFD_TRAN 
T2 WHERE T1.MBFILE = T2.MBFILE AND   T1.MBNRCD <> T2.MBNRCD') OUTPUT(*OUTFILE) O
UTFILE(QTEMP/DSPFD_DIFF)      

This will create a table with the below named columns:

 
MBFILE         10  
PROD_NRCD      10,0
TRAN_NRCD      10,0
DIFF_NRCD      11,0  

Note: The value specified within the double-quotes cannot contain spaces or the column name will be ignored and will default to the values shown in example 1.

==================================
MORE INFORMATION ON THIS TOPIC
==================================

The Best Web Links: tips, tutorials and more.

Ask your programming questions--or help out your peers by answering them--in our live discussion forums.


Dig Deeper on iSeries CL programming

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataCenter

Close