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

Need help on query


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
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
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: 6966
Location: porcelain throne

PostPosted: Tue Jun 09, 2009 3:57 pm
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
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
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: 6966
Location: porcelain throne

PostPosted: Tue Jun 09, 2009 4:40 pm
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
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: 6966
Location: porcelain throne

PostPosted: Tue Jun 09, 2009 5:40 pm
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
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 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