MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Format in year

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
shyamsaravan
Beginner


Joined: 12 May 2010
Posts: 44
Topics: 12
Location: India

PostPosted: Wed Oct 19, 2011 6:01 am    Post subject: Format in year Reply with quote

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
View user's profile Send private message
GuyC
Supermod


Joined: 27 May 2011
Posts: 35
Topics: 0

PostPosted: Wed Oct 19, 2011 6:08 am    Post subject: Reply with quote

max(year(current_date),year(dt_inp)) ?
Back to top
View user's profile Send private message
NASCAR9
Intermediate


Joined: 08 Oct 2004
Posts: 274
Topics: 52
Location: California

PostPosted: Thu Oct 20, 2011 6:45 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group