Quantcast
Channel: Toad for IBM DB2 Forum - Recent Threads
Viewing all articles
Browse latest Browse all 389

DB2 - First And Last Day Of Previous Quarter

$
0
0

Dear All,

I'm a SQL Server guy but we do have a system that uses DB2. As per the subject above, I can easily do this in Transact-SQL.But in DB2 SQL, I am having some difficulty.

So, looking ar the SQL below, this works fine:

SELECT d - DAYOFYEAR(d) DAYS + ((QUARTER(d) - 1) * 3) MONTHS - 3 MONTHS + 1 DAY
FROM (VALUES DATE('2017-04-21')) as D (d)

But once, I wrap in common table expression (that's what they are called in Transact-SQL) and I do a SELECT, I get no joy.

WITH StarDate

(

SELECT d - DAYOFYEAR(d) DAYS + ((QUARTER(d) - 1) * 3) MONTHS - 3 MONTHS + 1 DAY
FROM (VALUES DATE('2017-04-21')) as D(d)

)

SELECT  *  FROM StarDate -- This doesn't work!

Any ideas, please?

Regards.


Viewing all articles
Browse latest Browse all 389

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>