Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups 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: 6966
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: 186
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: 6966
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: 6966
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 Join in SQL Query vickey_dw DB2 2 Tue Jan 17, 2017 12:15 am
This topic is locked: you cannot edit posts or make replies. MQ setup query mohitsaini Java & MQSeries 4 Sun Jan 08, 2017 1:53 am
No new posts DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us