View previous topic :: View next topic
|
Author |
Message |
gansin
New User
Joined: 01 Oct 2009 Posts: 3 Location: Hyderabad
|
|
|
|
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 |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
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 |
|
|
gansin
New User
Joined: 01 Oct 2009 Posts: 3 Location: Hyderabad
|
|
|
|
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 |
|
|
gansin
New User
Joined: 01 Oct 2009 Posts: 3 Location: Hyderabad
|
|
|
|
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 |
|
|
Bharath Bhat
Active User
Joined: 20 Mar 2008 Posts: 283 Location: chennai
|
|
|
|
I think you are getting null indicators. Coalesce gives you a nullable column. |
|
Back to top |
|
|
|