Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Increment YEAR - SMALLINT column by 1 in certain condition

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
rohanthengal

Active User


Joined: 19 Mar 2009
Posts: 179
Location: Globe, India

PostPosted: Wed Jun 26, 2013 11:31 am    Post subject: Increment YEAR - SMALLINT column by 1 in certain condition
Reply with quote

I am in requirement to increment YEAR_COLUMN (defined as SMALLINT) column by 1 when YEAR part of CURRENT TIMESTAMP is greater.
So, i have tried below SQL. Please suggest if there can be other better/efficient approach to do this as i am new to these types of SQLs.

My SQL:
Code:

UPDATE TABLE_NAME
SET YEAR_COLUMN
( CASE WHEN CHAR(YEAR_COLUMN) < (CHAR(YEAR(CURRENT TIMESTAMP)))
           THEN YEAR_COLUMN = YEAR_COLUMN + 1
           ELSE YEAR_COLUMN
   END
)
WITH CS;


I doubt if i really need to convert YEAR - SMALL INT to CHAR before comparing with YEAR(CURRENT TIMESTAMP) ?

I cant test these as i want to place into design first for approval.
Back to top
View user's profile Send private message

Pandora-Box

Moderator


Joined: 07 Sep 2006
Posts: 1534
Location: Andromeda Galaxy

PostPosted: Wed Jun 26, 2013 11:55 am    Post subject:
Reply with quote

Quote:
I cant test these as i want to place into design first for approval.


Dont you have a place where you can test things??

And how would you ensure what ever placed in Design could work fine??
Back to top
View user's profile Send private message
rohanthengal

Active User


Joined: 19 Mar 2009
Posts: 179
Location: Globe, India

PostPosted: Wed Jun 26, 2013 12:24 pm    Post subject:
Reply with quote

Thats why i need help here.. It should be checked for concept and syntax first
Back to top
View user's profile Send private message
Pandora-Box

Moderator


Joined: 07 Sep 2006
Posts: 1534
Location: Andromeda Galaxy

PostPosted: Wed Jun 26, 2013 12:37 pm    Post subject:
Reply with quote

icon_sad.gif icon_sad.gif icon_sad.gif

Rohan you didnt get my point

what is stopping you from trying in the place where you test your codes ??

Personally it is a very bad idea to ask someone else to test the code for you to incorporate it in your design
Back to top
View user's profile Send private message
singhju

New User


Joined: 01 Dec 2010
Posts: 25
Location: Gurgaon

PostPosted: Wed Jun 26, 2013 1:45 pm    Post subject:
Reply with quote

I just ran the below SQL without using CHAR and it just worked fine.

Code:
SELECT                                                       
( CASE WHEN  YEAR(CURRENT DATE)  < (YEAR(CURRENT TIMESTAMP))
           THEN 1                                           
           ELSE 0                                           
   END                                                       
)                                                           
FROM SYSIBM.SYSDUMMY1                                       
WITH UR;                                                     
---------+---------+---------+---------+---------+---------+-
                                                             
---------+---------+---------+---------+---------+---------+-
          0                                                 
Back to top
View user's profile Send private message
gylbharat

Active Member


Joined: 31 Jul 2009
Posts: 565
Location: Bangalore

PostPosted: Wed Jun 26, 2013 6:07 pm    Post subject:
Reply with quote

Quote:

UPDATE TABLE_NAME
SET YEAR_COLUMN
( CASE WHEN CHAR(YEAR_COLUMN) < (CHAR(YEAR(CURRENT TIMESTAMP)))
THEN YEAR_COLUMN = YEAR_COLUMN + 1
ELSE YEAR_COLUMN
END
)
WITH CS;




I think isolation level is only used for select queries. Update queries need exclusive lock.
Back to top
View user's profile Send private message
rohanthengal

Active User


Joined: 19 Mar 2009
Posts: 179
Location: Globe, India

PostPosted: Fri Jun 28, 2013 11:40 pm    Post subject:
Reply with quote

yes, think so.. i tried above query in SPUFI using select and found few small corrections in above code:
1. no need to convert into CHAR for comparison
2. YEAR_COLUMN + 1 IS ENOUGH.. NO NEED TO WRITE YEAR_COLUMN = YEAR_COLUMN + 1
3. NO NEED OF ELSE CONSTRUCT AS WE DONT NEED TO CHANGE IT...
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts SORT to append Month and YEAR in MMYY... tisamf DFSORT/ICETOOL 1 Wed Mar 08, 2017 4:46 pm
No new posts Joinkeys with condition scdinesh DFSORT/ICETOOL 10 Tue Feb 14, 2017 12:20 am
No new posts 2 byte YEAR from Y'DATE2' field tecnokrat DFSORT/ICETOOL 2 Tue Feb 07, 2017 12:05 pm
This topic is locked: you cannot edit posts or make replies. DB2 query Using Recursion, Converting... smilewithashu2 DB2 3 Tue Jan 03, 2017 12:50 pm
No new posts SQZ pipe delimited file with 1 column... Rick Silvers DFSORT/ICETOOL 6 Sun Nov 06, 2016 8:11 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us