View previous topic :: View next topic
|
Author |
Message |
mfstudent1 Currently Banned New User
Joined: 03 Mar 2006 Posts: 18
|
|
|
|
I want to load a DB2 table with a null value for a decimal column on it.
In the Load JCL,can we use the NULLIF statement to populate NULL value for a decimal field.
If yes,Please help me with the format of the statement.
Thanks |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
mfstudent1 wrote: |
I want to load a DB2 table with a null value for a decimal column on it.
In the Load JCL,can we use the NULLIF statement to populate NULL value for a decimal field.
If yes,Please help me with the format of the statement.
Thanks |
Is the column defined as nullable? |
|
Back to top |
|
|
mfstudent1 Currently Banned New User
Joined: 03 Mar 2006 Posts: 18
|
|
|
|
Yes it is defined as a Nullable column |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
How are going to tell when the column is null and when it is not? That is the condition you need to enter in the NULLIF statement. |
|
Back to top |
|
|
mfstudent1 Currently Banned New User
Joined: 03 Mar 2006 Posts: 18
|
|
|
|
Thanks for the update.
But i wanted to know how to use the NULLIF statement for a decimal column.
I have used nullif for other data types.But decimal field is always a comp-3 field.
How shud I specify the attributes? |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
mfstudent1 wrote: |
Thanks for the update.
But i wanted to know how to use the NULLIF statement for a decimal column.
I have used nullif for other data types.But decimal field is always a comp-3 field.
How shud I specify the attributes? |
If the column is null for a row then there is no value for that column in that row just a null indicator with a -1 value. |
|
Back to top |
|
|
mfstudent1 Currently Banned New User
Joined: 03 Mar 2006 Posts: 18
|
|
|
|
I want to populate the Null value using a load jcl.
I just wanted to know how to use nullif condition for comp-3 field |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
mfstudent1 wrote: |
I want to populate the Null value using a load jcl.
I just wanted to know how to use nullif condition for comp-3 field |
You use the NULLIF condition for a decimal column the same as you would for any other column.
Column definition
Code: |
TOT_NSW_DOLLARS DEC(7,2),
|
then the load would be
Code: |
"TOT_NSW_DOLLARS " POSITION( 00603:00611) DECIMAL EXTERNAL(09,02) NULLIF(00602)=X'FF',
|
What don't you understand? |
|
Back to top |
|
|
mfstudent1 Currently Banned New User
Joined: 03 Mar 2006 Posts: 18
|
|
|
|
Thanks a lot for the response.
I will try this and let you know the update... |
|
Back to top |
|
|
stodolas
Active Member
Joined: 13 Jun 2007 Posts: 631 Location: Wisconsin
|
|
|
|
mfstudent1: Based on what Craq Giegerich said, you need to ensure that you have a byte before your field that is set to x'FF' if you want a NULL. It won't matter what the value of the actual field is then. |
|
Back to top |
|
|
mfstudent1 Currently Banned New User
Joined: 03 Mar 2006 Posts: 18
|
|
|
|
But i want to check the actual value in comp-3 field and then populate a null for the column |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
mfstudent1 wrote: |
But i want to check the actual value in comp-3 field and then populate a null for the column |
I will ask AGAIN. How are you going to determine if the field is going to be null? And what is the format of the field? |
|
Back to top |
|
|
stodolas
Active Member
Joined: 13 Jun 2007 Posts: 631 Location: Wisconsin
|
|
|
|
If the value is stored comp-3 it should be a valid numeric, why NULL the DB column when you have a valid value?
Do you want NULL if that value is negative or 0 or 12.789889? What is the rule for NULLING? |
|
Back to top |
|
|
mfstudent1 Currently Banned New User
Joined: 03 Mar 2006 Posts: 18
|
|
|
|
My question is straight forward.
is there a way to populate a null value in the decimal column.I don't want to use another field value to populate null value in this field.
I hope iam clear |
|
Back to top |
|
|
stodolas
Active Member
Joined: 13 Jun 2007 Posts: 631 Location: Wisconsin
|
|
|
|
Your question is far from straight forward.
To answer your "straight forward question", yes there is a way to populate a NULL value in a decimal column.
However you are also saying you want to populate based on a 'comp-3' field in a file. By saying 'based on', you are implying that you are using some value to determine whether or not a NULL needs to be inserted. NULLIF requires some sort of conditional check, hence the "IF" part of the statement.
What do you want to check to determine whether or not the NULL is to be inserted? The value in the COMP-3? If so what cases will result in a NULL being inserted?
Do you want every row to have a NULL for that column? This is far easier to accomplish because no NULLIF is needed, just specify NULL for that column. |
|
Back to top |
|
|
mfstudent1 Currently Banned New User
Joined: 03 Mar 2006 Posts: 18
|
|
|
|
Thanks for the update.
Can I always populate a null value for nullable column which is a decimal one.Here I dont want to check the data in the field .I Just want to populate a null value always |
|
Back to top |
|
|
stodolas
Active Member
Joined: 13 Jun 2007 Posts: 631 Location: Wisconsin
|
|
|
|
Have you tried coding NULLIF (1=0) |
|
Back to top |
|
|
mfstudent1 Currently Banned New User
Joined: 03 Mar 2006 Posts: 18
|
|
|
|
Wat do you mean by (1=0) here? |
|
Back to top |
|
|
stodolas
Active Member
Joined: 13 Jun 2007 Posts: 631 Location: Wisconsin
|
|
|
|
Whoops that should be NULLIF(1=1) since that will always be true or maybe NULLIF(TRUE) or have the DBA set the column to have a default value of NULL when a value is not provided. |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
If you want every row to be null in that column then don't even have it in the load! |
|
Back to top |
|
|
stodolas
Active Member
Joined: 13 Jun 2007 Posts: 631 Location: Wisconsin
|
|
|
|
If the column isn't wasn't created to have a default of NULL (can you even do that) don't you need to specify it still as part of the load? |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
stodolas wrote: |
If the column isn't wasn't created to have a default of NULL (can you even do that) don't you need to specify it still as part of the load? |
If the column is nullable then the default is NULL. |
|
Back to top |
|
|
|