Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Need help on query

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

New User


Joined: 20 Feb 2009
Posts: 51
Location: Chennai

PostPosted: Tue Jun 09, 2009 2:58 pm    Post subject: Need help on query
Reply with quote

Can any one help me in providing a query.


I have written query to select the maxmimum value of one column in a table with certain condition..

(SELECT MAX(COMP_STAT_SEQ_NBR)+1
FROM VTCOMP
WHERE COMP_STATUS_MNE = 'HISTOR' AND CON_NBR = '056044572 0'),


It is running fine if it found the row which satisfy the criteria.

If the criteria is not satisfied(No valid row in a table) . The query errored with THE OBJECT COLUMN CANNOT CONTAIN NULL VALUES.

Can any one help me out
Back to top
View user's profile Send private message

dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6968
Location: porcelain throne

PostPosted: Tue Jun 09, 2009 3:57 pm    Post subject:
Reply with quote

maybe using VALUE, and the substitute for NULL would be 1
Back to top
View user's profile Send private message
Satheeshkumar

New User


Joined: 20 Feb 2009
Posts: 51
Location: Chennai

PostPosted: Tue Jun 09, 2009 4:09 pm    Post subject:
Reply with quote

Could you please give some more information
Back to top
View user's profile Send private message
Raghu navaikulam

Active User


Joined: 27 Sep 2008
Posts: 193
Location: chennai

PostPosted: Tue Jun 09, 2009 4:30 pm    Post subject: Reply to: Need help on query
Reply with quote

Hi Satheeshkumar

You can use VALUE function along with MAX function to get rid of this issue.
Eg. SELECT MAX(VALUE(Column_name, xxxx)) FROM TABLE_NAME ...

Here xxxx is the value you have to provide if the column is NULL.
And the value you provided should match the datatype of the column.

Hope this will help.

Regards
Raghu
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6968
Location: porcelain throne

PostPosted: Tue Jun 09, 2009 4:40 pm    Post subject:
Reply with quote

IFNULL
COALESCE or VALUE
Back to top
View user's profile Send private message
Satheeshkumar

New User


Joined: 20 Feb 2009
Posts: 51
Location: Chennai

PostPosted: Tue Jun 09, 2009 5:08 pm    Post subject:
Reply with quote

Still i am getting Null values. Please see the screen shot below

---------+---------+---------+---------+---------+---------+----
SELECT MAX(VALUE(COMP_STAT_SEQ_NBR,0))
FROM E0384DBA.CYVTCOMP
WHERE COMP_STATUS_MNE = 'HISTOR' AND CON_NBR = '03Y044631 0';




DSNE610I NUMBER OF ROWS DISPLAYED IS 1
DSNE616I STATEMENT EXECUTION WAS SUCCESSFUL, SQLCODE IS 100
---------+---------+---------+---------+---------+---------+----
--
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6968
Location: porcelain throne

PostPosted: Tue Jun 09, 2009 5:40 pm    Post subject:
Reply with quote

SELECT VALUE(MAX(COMP_STAT_SEQ_NBR),0)
Back to top
View user's profile Send private message
maggiebms

New User


Joined: 23 May 2005
Posts: 16

PostPosted: Tue Jun 09, 2009 7:01 pm    Post subject: Reply to: Need help on query
Reply with quote

Hi,
You can use COALESCE(MAX(COMP_STAT_SEQ_NBR),0) also.

Regards,
Maggie J
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 Create procedure issues -628 when add... chandraBE DB2 1 Mon Sep 18, 2017 12:16 pm
No new posts Can we limit length in concatenation ... balaji81_k DB2 7 Tue Aug 22, 2017 2:50 am
No new posts Need DB2 query to fetch previous row ! Chandan1993 DB2 10 Sat Jun 03, 2017 10:43 am
No new posts JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm
No new posts SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us