IBM Mainframe Forum Index
 
Register
 
IBM Mainframe Forum Index Mainframe: Search Log in to check your private messages Log in
 

Increment YEAR - SMALLINT column by 1 in certain condition


 
IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
rohanthengal

Active User


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

PostPosted: Wed Jun 26, 2013 11:31 am
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: 1566
Location: Andromeda Galaxy

PostPosted: Wed Jun 26, 2013 11:55 am
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: 195
Location: Globe, India

PostPosted: Wed Jun 26, 2013 12:24 pm
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: 1566
Location: Andromeda Galaxy

PostPosted: Wed Jun 26, 2013 12:37 pm
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
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
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: 195
Location: Globe, India

PostPosted: Fri Jun 28, 2013 11:40 pm
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 All times are GMT + 6 Hours
Forum Index -> DB2
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Forum Replies
No new posts Can we Insert duplicates in Primary U... DB2 0
No new posts Converting Hex to PD Special Condition SYNCSORT 3
No new posts COnvert a column with mix of hex ,cha... DB2 5
No new posts Print next line strings when a condit... DFSORT/ICETOOL 9
No new posts Need SQL for two latest records havin... DB2 10

Back to Top