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

Select spaces for a nullable date field.


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
muffirulz

New User


Joined: 14 Sep 2005
Posts: 74
Location: Atlanta, (USA)

PostPosted: Tue Jul 07, 2009 8:45 pm
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
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: 1020
Location: India

PostPosted: Wed Jul 08, 2009 10:47 am
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: 1353
Location: Israel

PostPosted: Wed Jul 08, 2009 3:04 pm
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Replacing 'YYMMDD' with date, varying... SYNCSORT 3
No new posts Modifying Date Format Using DFSORT DFSORT/ICETOOL 9
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts Need to convert date format DFSORT/ICETOOL 20
No new posts Dynamically pass table name to a sele... DB2 2
Search our Forums:

Back to Top