IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Addition in a query


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

Active User


Joined: 22 Dec 2005
Posts: 116

PostPosted: Tue Jan 15, 2008 2:03 pm
Reply with quote

I want to add 1 to a colum selected in a query.

The query is like :
SELECT MAX(EMPNO) + 1
FROM UPPSU.TKGFIDSG
WHERE EMPNO LIKE 'C%'

But here the field EMPNO is a character field. So adding 1 to this in the wuery is failing. Also I am selecting only Those EMPNO whose first character is a 'C'. So can anyone get me a solution houw to 1 one to the maximum value of EMPNO selected.

Like if the max value of EMPNO is C111223333, the value after addition should be C111223334.

Please let me know whether this is possible by making some changes to the query.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Tue Jan 15, 2008 2:21 pm
Reply with quote

as usual the forum is asked to put a remedy to poor application design!
if the field is char then it is just that .. a char
the request made by the application analyst is to use a kind word illogic,

if You search the net You might find some useful ideas on how to
write an UDF to do a casting from char to integer,
("db2 query cast char integer")

but since You are just retrieving the column, I guess it would be simpler to carry on
the arithmetics outside the query
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Tue Jan 15, 2008 9:50 pm
Reply with quote

Use substr to get the numeric part, then convert to numeric, add, then reconcatenate the "C" back in front.
Back to top
View user's profile Send private message
abhishekmdwivedi

New User


Joined: 22 Aug 2006
Posts: 95
Location: india

PostPosted: Wed Jan 16, 2008 5:40 pm
Reply with quote

pjnithin,

The design is certainly a poor one but following code may do what you asked for :

Code:

SELECT INT(SUBSTR('C111222333',2,9))+1 FROM SYSIBM.SYSDUMMY1;
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts RC query -Time column CA Products 3
No new posts Dynamically pass table name to a sele... DB2 2
No new posts Query on edit primary command CLIST & REXX 5
No new posts Query on edit primary command CLIST & REXX 1
No new posts Issue with EXEC CICS QUERY SECURITY c... CICS 6
Search our Forums:

Back to Top