× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Not all recursive SQL statements need to be complex.

Here is a small recursive SQL I used a few years ago.

I had a file that contained information on a 15 minute interval.
I needed to pull the information from the file for all 15 minute intervals, even though there may be gaps in the data.

So this recursive statement builds all of the 15 minute periods between two timestamps:

WITH TS_DIM2 (HTS) AS (
VALUES (TIMESTAMP('2015-06-14 00:00:00.000000') )
UNION ALL SELECT HTS + 15 MINUTES FROM TS_DIM2 WHERE HTS < TIMESTAMP('2015-06-15 14:45:00.000000'))
, TS_DIM (HDATE, HTIME)AS (SELECT DISTINCT DATE(HTS), TIME(HTS) FROM TS_DIM2)
SELECT * FROM TS_DIM


I've even been able to find a use for a recursive statement that just generates a list of the letters in the alphabet.
These may seem overly trivial, but you can use these types of statements as a CTE of keys. Then Left Join or Exception Join to other data and be able to determine when you are missing certain keys.


Chris Hiebert
Senior Programmer/Analyst
Disclaimer: Any views or opinions presented are solely those of the author and do not necessarily represent those of the company.
-----Original Message-----
From: MIDRANGE-L [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of Hoteltravelfundotcom
Sent: Thursday, June 29, 2017 11:42 AM
To: Midrange Systems Technical Discussion <midrange-l@xxxxxxxxxxxx>
Subject: Recursive SQL on the i

HI I was interested in how you might be using Recursive SQL on the i.
From what I have read on the IBM web site on this topic,. it seems most used in very large enormous, complex, data sets.

My way has always been to break the task into smaller manageable parts.

Perhaps someone who really knows can explain this better.

Thank you,
Joe

As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

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.