View previous topic :: View next topic |
Author |
Message |
shyamsaravan Beginner
Joined: 12 May 2010 Posts: 44 Topics: 12 Location: India
|
Posted: Wed Oct 19, 2011 6:01 am Post subject: Format in year |
|
|
Hi;
Given query gives the result like
Code: |
SELECT T1.*
, YEAR(current_date)
+ 1
+ SIGN( YEAR(DT_INP) - YEAR(current_date)-1 ) TEMP_year
FROM TABLE1 T1
|
Given Result
Code: |
TEMP_YEAR DT_INP
----------- ------------
2011 2008-01-12
2011 2009-02-10
2011 2010-03-11
2011 2011-10-13
2012 2012-11-03
2013 2013-10-12
2013 2014-09-11
2013 2015-01-05
2013 2016-01-06
2013 2020-01-07
|
But i need the below result set
Expected Result set
Code: |
TEMP_YEAR DT_INP
----------- ------------
2011 2008-01-12
2011 2009-02-10
2011 2010-03-11
2011 2011-10-13
2012 2012-11-03
2013 2013-10-12
2014 2014-09-11
2015 2015-01-05
2016 2016-01-06
2020 2020-01-07
|
Please help me,where to need to change the above query
Thanks in advance |
|
Back to top |
|
|
GuyC Supermod
Joined: 27 May 2011 Posts: 35 Topics: 0
|
Posted: Wed Oct 19, 2011 6:08 am Post subject: |
|
|
max(year(current_date),year(dt_inp)) ? |
|
Back to top |
|
|
NASCAR9 Intermediate
Joined: 08 Oct 2004 Posts: 274 Topics: 52 Location: California
|
Posted: Thu Oct 20, 2011 6:45 pm Post subject: |
|
|
how about this:
Case
When year(current date) > year(dt_imp) then year(current date)
ELSE year(dt_imp)
END
,dt_imp _________________ Thanks,
NASCAR9 |
|
Back to top |
|
|
|
|