×
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.
This might work as a query, but not within a view:
WITH
cte1 AS
(SELECT code, begindate
FROM qtemp/t1
GROUP BY code, begindate),
cte2 AS
(SELECT b.code, a.enddate
FROM qtemp/t1 a JOIN cte1 b USING(code,begindate)
WHERE b.begindate <> a.enddate)
SELECT * FROM cte1
UNION ALL
SELECT * FROM cte2
ORDER BY 1,2
So try this instead:
CREATE VIEW myView (code,theDate) AS (
SELECT code, begindate
FROM qtemp/t1
GROUP BY code, begindate
UNION ALL
SELECT a.code, a.enddate
FROM qtemp/t1 a JOIN
(SELECT code, begindate
FROM qtemp/t1
GROUP BY code, begindate) b USING(code,begindate)
WHERE a.enddate <> b.begindate)
Then to get it in the order you want, you'll need to add the ORDER BY to the
SELECT that goes against this view:
SELECT * FROM myView ORDER BY 1,2
Hth, Elvis
Celebrating 11-Years of SQL Performance Excellence on IBM i, i5/OS and
OS/400
www.centerfieldtechnology.com
-----Original Message-----
Subject: SQL Column ranges into rows
Wresting with some database conversion issues. Actually, I don't want
to the database to change, I want my application that accesses these
different databases to change as little as possible so building views to
present the data in a similar fashion is what I am after.
I have a table that could either be in this format:
code, begin date, end date
'test', 20080115, 20080118
What I would like do is have a view that structures the second table
like the first. If the two dates are the same, you get one row with
code and date. If you have a range of dates that span 6 days (for
example), then there would be 6 rows generated by the view.
Is this possible?
Thanks
Pete
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 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.