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
 

 

Select spaces for a nullable date field.

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

New User


Joined: 14 Sep 2005
Posts: 74
Location: Kentucky, USA

PostPosted: Tue Jul 07, 2009 8:45 pm    Post subject: Select spaces for a nullable date field.
Reply with quote

Hi,

I have a table in which the end-date field is nullable. While doing a select I want to have spaces when the end-date is null. I ahve tried using the value clause but it says that it requires a valid date.

For example the below query is termed as invalid by DB2

Code:

SELECT A.EFF-DATE
      ,VALUE(A.END-DATE,'          ')
FROM EMPLOYEE A


Instead I have to use the below query

Code:

SELECT A.EFF-DATE
      ,VALUE(A.END-DATE,'01-01-0001')
FROM EMPLOYEE A


Please let me know if I am missing a command or syntax to select end-date as spaces whenever it is null.

Thnx
M
Back to top
View user's profile Send private message

dbzTHEdinosauer

Global Moderator


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

PostPosted: Tue Jul 07, 2009 8:54 pm    Post subject:
Reply with quote

spaces will only work with CHAR datatype.
You need to cast the data-column to char for the VALUE clause to work.
even then I am not sure (I am not going to test it).

if that does not work, use a CASE statement. (But that may not work either).

it would help to know the complete sql (generally) and how you are using it.

if it is imbedded sql I would just use the program to move spaces if null indicator on.
Back to top
View user's profile Send private message
sushanth bobby

Senior Member


Joined: 29 Jul 2008
Posts: 1013
Location: India

PostPosted: Wed Jul 08, 2009 10:47 am    Post subject:
Reply with quote

M,

Try this, make modifications according to your need
Code:
  SELECT FIRSTNME, COALESCE(CHAR(HIREDATE),'NO DATA') FROM BOBT1.EMPLOYEE;


Sushanth
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1224
Location: Israel

PostPosted: Wed Jul 08, 2009 3:04 pm    Post subject:
Reply with quote

Even if you're not running your query in a program, it is always useful to read the manual: Using indicator variables with host variables
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 INVALID FIELD OR CONSTANT IN SORTOF ?? Ron Klop DFSORT/ICETOOL 8 Wed Jan 11, 2017 3:44 pm
No new posts Performing arithmetic on input field zh_lad DFSORT/ICETOOL 31 Tue Dec 06, 2016 8:04 pm
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts TOT & DATE parameter in ICEMAN hemanthj642 DFSORT/ICETOOL 4 Mon Nov 14, 2016 5:19 am
No new posts Two Selects in a single select query Rohit Umarjikar DB2 1 Fri Nov 04, 2016 8:46 pm


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