Every once and a while, I need to use the following technique and every
time it takes me a few minutes to find the right syntax.
The idea is to build a temporary table in memory, from text data rather
than actually inserting it into an actual (temporary) table.
There's two valid syntaxes
WITH X(foo, bar, baz) AS (
VALUES (0, 1, 2), (3, 4, 5), (6, 7, 8)
) SELECT * FROM X;
or
SELECT * FROM TABLE (
VALUES (0, 1, 2), (3, 4, 5), (6, 7, 8)
) X(foo, bar, baz);
This "table value constructor" was added to the SQL99 standards. Not sure
when it made it to DB2 for i; perhaps v5r4 but it certainly works in 7.1.
But DB2 for LUW has apparently had it since v7.2.8.
Hopefully, someone else will find this useful and that in the future I'll
be able to find this post again quickly :)
Charles
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact
[javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.