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: 176
Location: Pune, Maharashtra, 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: 1529
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: 176
Location: Pune, Maharashtra, 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: 1529
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: 176
Location: Pune, Maharashtra, 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 SQZ pipe delimited file with 1 column... Rick Silvers DFSORT/ICETOOL 2 Sun Nov 06, 2016 8:11 pm
This topic is locked: you cannot edit posts or make replies. How to pass the previous month date i... Suganya87 DFSORT/ICETOOL 5 Mon Oct 31, 2016 4:13 pm
No new posts Wishing everyone a very Happy Diwali ... Rohit Umarjikar General Talk & Fun Stuff 1 Sat Oct 29, 2016 1:54 am
This topic is locked: you cannot edit posts or make replies. Checking wether a string starts from ... sundaram.naveen CLIST & REXX 9 Thu Oct 06, 2016 11:56 am
No new posts Add system date inside of a PS file a... pramitdas DFSORT/ICETOOL 5 Sun Aug 28, 2016 12:06 am


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