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

Unloading data along with coalesce function


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

New User


Joined: 01 Oct 2009
Posts: 3
Location: Hyderabad

PostPosted: Thu Oct 01, 2009 2:52 pm
Reply with quote

Hi,

My requirement is to unload selected data from DB2 table .When it is Null I want default value of '-1' to be assigned to it. For this I use Coalesce Function.Whenever I use this I am getting default values assigned but additional 2 blank bytes are added to the unload data.Please confirm whether by default it will be padded or I am going wrong somewhere.
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Thu Oct 01, 2009 3:24 pm
Reply with quote

Hi,

It would be nice if you show us the query you've used and the results you get. Please use BBcode tags when you post them, that would make them readable.

Quote:
Whenever I use this I am getting default values assigned but additional 2 blank bytes are added to the unload data.
I'm ot sure what should I conculde from this. COALESCE returns the first argument that is not null.

The arguments are evaluated in the order in which they are specified, and the result of the function is the first argument that is not null. The result can be null only if all the arguments can be null, and the result is null only if all the arguments are null. The selected argument is converted, if necessary, to the attributes of the result. For example, this query
Code:
   SELECT A, COALESCE(B, 0)
     FROM table
will return a value of zero for column B if there is some value for which it is missing in some row (that is, null).
Back to top
View user's profile Send private message
gansin

New User


Joined: 01 Oct 2009
Posts: 3
Location: Hyderabad

PostPosted: Thu Oct 01, 2009 4:33 pm
Reply with quote

Thanks for your reply. Due to some reasons I will not be able to post the code directly.

I am using it in below way

Select COALESCE(A , '-1' )
COALESCE(B, '-1' )
C

Where A is of type x(9),B x(9), C x(3)

My result is 123456789_ _ 12345678_ _ ABC
( last 2 denotes the blank field which I am getting between those 2 fields)

When field A has value it is displaying the value and when it is null it is displaying '-1'. Same case for B.
Back to top
View user's profile Send private message
gansin

New User


Joined: 01 Oct 2009
Posts: 3
Location: Hyderabad

PostPosted: Thu Oct 01, 2009 5:08 pm
Reply with quote

Instead of the above method , do we have any other way to assign the default value to the null field during unload itself ( For unload I am using DSNTIAUL). I am doing selected unload form more than 4 tables joined together.
Back to top
View user's profile Send private message
Bharath Bhat

Active User


Joined: 20 Mar 2008
Posts: 283
Location: chennai

PostPosted: Wed Oct 07, 2009 11:11 am
Reply with quote

I think you are getting null indicators. Coalesce gives you a nullable column.
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 Store the data for fixed length COBOL Programming 1
No new posts Data set Rec-Cnt and Byte-Cnt Testing & Performance 2
No new posts SCOPE PENDING option -check data DB2 2
No new posts Check data with Exception Table DB2 0
No new posts Calling an Open C library function in... CICS 1
Search our Forums:

Back to Top