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

RE: date question

$
0
0

How does this work?  Not sure about performance, but I think its what you want.


with cte_dates as
(
Select cast('5/22/2018' as date) as start_date
from sysibm.sysdummy1

union all

Select cast('3/1/2003' as date) as start_date
from sysibm.sysdummy1

union all

Select cast('6/4/2006' as date) as start_date
from sysibm.sysdummy1
)
Select a.start_date,
case
--last year
when month(a.start_datE) <= month(current timestamp)
then month(a.start_date)
|| '/1/'
|| cast(cast(year(current timestamp)as int) -1 as char(4))
--2 years ago
else
month(a.start_date)
|| '/1/'
|| cast(cast(year(current timestamp)as int) -2 as char(4))
end as begin_date,
case
--current year
when month(a.start_datE) <= month(current timestamp)
then month(a.start_date)
|| '/1/'
|| year(current timestamp)
--last year
else
month(a.start_date)
|| '/1/'
|| cast(cast(year(current timestamp)as int) -1 as char(4))
end as end_date
from cte_dates a


Viewing all articles
Browse latest Browse all 389

Trending Articles



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