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: 6970
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: 6970
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: 6970
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 query to fetch record which has only ... maxsubrat DB2 12 Mon Dec 11, 2017 5:03 pm
No new posts How to query MAXGENS of an existing P... Chuchulo Hatyzak JCL & VSAM 4 Wed Nov 22, 2017 10:23 pm
No new posts Native SQL Query kishpra DB2 1 Wed Nov 22, 2017 8:38 pm
No new posts Query on IEFBR14 with GDG Ashishpanpaliya JCL & VSAM 4 Tue Nov 07, 2017 8:34 pm
No new posts Query on XMITIP abdulrafi All Other Mainframe Topics 1 Wed Oct 25, 2017 6:54 pm

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