View previous topic :: View next topic
|
Author |
Message |
abhiyanta
New User
Joined: 18 Apr 2006 Posts: 11 Location: pune
|
|
|
|
Hi,
Please help me to solve this.
I want to INSERT null value into DB2 Table for specified column Thru Cobol-Db2 program, and not for all row of that table, only some specific rows need to insert with null... |
|
Back to top |
|
|
rpuhlman
New User
Joined: 11 Jun 2007 Posts: 80 Location: Columbus, Ohio
|
|
|
|
Code: |
INSERT INTO table-name
(column-name1,
column-name-nulls, ....)
VALUES (:host-var,
NULL, ....) |
|
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
do any of you guys test your suggestions or do you just type this garbage in to up your post count?
abhiyanta,
use the null indicator syntax within your values clause of the INSERT statement.
:host-variable :null-indicator-variable
no comma, only a space between the capatible host variable for the column and the host variable used as the null-indicator-variable. The null indicator variable should be defined as binary, s9(4), with a value of -1. |
|
Back to top |
|
|
rpuhlman
New User
Joined: 11 Jun 2007 Posts: 80 Location: Columbus, Ohio
|
|
|
|
Wow ... you just impressed the crap out of me!!! BTW ... before you jump on somebody ... you need to read up on YOUR facts ... I might be a jeep on this site, but not in this business. It was not intended to be the EXACT code, just an EXAMPLE ... something that MIGHT help. Just because it does not agree with your style of coding doesn't make it wrong or give you the right to disrespect someone you don't know. |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
rpuhlman wrote: |
Wow ... you just impressed the crap out of me!!! BTW ... before you jump on somebody ... you need to read up on YOUR facts ... I might be a jeep on this site, but not in this business. It was not intended to be the EXACT code, just an EXAMPLE ... something that MIGHT help. Just because it does not agree with your style of coding doesn't make it wrong or give you the right to disrespect someone you don't know. |
I have to agree with dbzTHEdinosauer, your example isn't a good example of anything.
|
|
Back to top |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1042 Location: Richmond, Virginia
|
|
|
|
Wasn't the example just trying to say that the token NULL will represent a null value?
It's an insert, so just listing values is OK. Why need a var and an ind-var? |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
I apologize to rpuhlman. His post is ok and SQL is accurate.
my mouth overloaded my ass.
In my attempt to provide flexible code I overlooked the fact that using NULL in the VALUE clause is legal, ok and will work.
With imbedded SQL you need to use the host-var ind-var syntax if you ever want to enter a value for that column.
Setting the ind-var to -1 will set the Column to NULL (the value of the host-var has no effect and is ignored)
and
setting the ind-var to zero and populating the host-var and allows you to populate the column with the value contained in the host-var. |
|
Back to top |
|
|
dr_te_z
New User
Joined: 08 Jun 2007 Posts: 71 Location: Zoetermeer, the Netherlands
|
|
|
|
Don't mention! Really, don't mention.
Just insert your row only specifying only those columns which are not nulls allowed (typical primary key) and all the remaining columns get a null-value, exactly as topicstarter requested. All the other answers might be correct but just too much |
|
Back to top |
|
|
revel
Active User
Joined: 05 Apr 2005 Posts: 135 Location: Bangalore/Chennai-INDIA
|
|
|
|
Just to add some thoughts on above,
we can INSERT null values in diffrent ways,
1) As suggested by rpuhlman
Code: |
INSERT INTO table-name
(column-name1,
column-name-nulls, ....)
VALUES (:host-var,
NULL, ....) |
2) Use only the columns to which we have to populate information
Ex;
Consider a TABLE A having 3 Columns COL1, COL2, COL3
To INSERT NULL Values for COL2(Don't include COL2 in a query)
Use following Query
Code: |
INSERT INTO table-name
(COL1,COL3)
VALUES (:host-var1,:host-var3) |
3) Use Comma(,) in VALUE Clause like
Code: |
INSERT INTO table-name
(COL1,COL2,COL3)
VALUES (:host-var1, ,:host-var3) |
Any suggestion is welcomed
Regards,
Raghavendra |
|
Back to top |
|
|
rpuhlman
New User
Joined: 11 Jun 2007 Posts: 80 Location: Columbus, Ohio
|
|
|
|
Dick,
Forget about it. Your are obviously very knowledgeable. I have read many of your posts and know you have a great deal to offer. I would have preferred that my response to you be in private, but have no way of contacting you. Anyway, I will continue to point many of my peers in your direction ... Thank you for all your time and effort on this site.
Thanks again,
Rick |
|
Back to top |
|
|
|