|
|
![]() |
|
|
|
|
||
|
SQL's One-Row, One-Column Table Hey, Ted: In the October 25 Midrange Guru article, "SQL to the Rescue!", a reader named Jeff provides an example that requires a file with one record. IBM provides such a file for just that purpose:
It's called QSQPTABL. -- Yannick Thanks for the information, Yannick. QSQPTABL is in library QSYS2. It has one column (field), which is a four-byte integer field called INTCOL (INTEGER_COLUMN). The only row in the table has the value 1. It occurred to me that this technique is probably worth further exploration. SQL has a rich set of scalar functions, and IBM adds more functions with new releases. Besides, enterprising programmers can write functions of their own. Learning to use this selection technique against one record provides a way to tap into these functions. Here are three more examples to help the reader who is not accustomed to using SQL to carry out internal data conversions in RPG. The first example uses SQL's DAYOFWEEK function, which returns a number from 1 to 7 to indicate Sunday through Saturday:
* To compile:
* CRTSQLRPGI ... DATFMT(*ISO)
D weekday s 10i 0
D duedate s d
D
C/exec sql
C+ select dayofweek(:duedate)
C+ into :weekday
C+ from qsys2/qsqptabl
C/end-exec
The second example produces a hex representation of a character string. If charvalue is ARITHMETIC, hexvalue becomes C1D9C9E3C8D4C5E3C9C3: D hexvalue s 20a D charvalue s 10a D C/exec sql C+ select hex(:charvalue) C+ into :hexvalue C+ from qsys2/qsqptabl C/end-exec C The third example uses the TRIM function to remove leading zeros from a number stored in a character variable. If NBR has the value 000000048.20, EDITEDNBR takes the value 48.20 and has a length of five bytes: D editednbr s 20a varying D nbr s 12a D C/exec sql C+ select trim(leading '0' from :nbr) C+ into :editednbr C+ from qsys2/qsqptabl C/end-exec IBM's online SQL Reference for V5R2, "DB2 Universal Database for iSeries SQL Reference," has a complete list of functions. Thanks to Jeff and Yannick for sharing this technique. -- Ted
|
Editors
Contact the Editors |
|
Last Updated: 10/30/02 Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved. |