Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I am trying to insert data into certain columns of my table and i keep getting the below error message.

Cannot insert the value NULL into column 'RKEY', table 'Test-Live.dbo.tempWIPAeroV1'; column does not allow nulls. INSERT fails.


I am not even trying to enter anything in the RKEY column

What I have tried:

<pre> Insert into tempWIPAeroV1 (WIPMATL,WIP_sold) (select Material_cost ,Sold_cost  from NewValues  join tempWIPAeroV1 on  tempWIPAeroV1.RKEY = NewValues.RKEY )
Posted
Updated 30-Nov-17 17:15pm
Comments
Santosh kumar Pithani 30-Nov-17 23:08pm    
AS your using inner join on condition of "tempWIPAeroV1.RKEY = NewValues.RKEY " so how u get null records on Rkey column? use filter condition to avoid null records.

The column RKey in your table does not allow a NULL value.
When you insert a new record & do not provide a value for this field, the database will set the value to NULL.

Therefore you have 3 options;
a) Edit the field to accept a NULL value as follows
1) Open SQL Enterprise Manager
2) Right-click the Table & select Design
3) Scroll to the column & tick the Allow Nulls field
4) Close the table - click Yes when prompted to save
b) Set a Default value for the field
1) Open SQL Enterprise Manager
2) Right-click the Table & select Design
3) Select the correct column
4) Set the Default value or Binding field based on the field type
5) Close the table - click Yes when prompted to save
c) Update your Insert statement as below (example only)
SQL
Insert into tempWIPAeroV1 (WIPMATL,WIP_sold, RKey) (select Material_cost ,Sold_cost, RKEY  from NewValues  join tempWIPAeroV1 on  tempWIPAeroV1.RKEY = NewValues.RKEY )


Kind Regards
 
Share this answer
 
Comments
Richard Deeming 1-Dec-17 13:35pm    
SQL Enterprise Manager? That brings back some not-so-fond memories!

It's called SQL Management Studio these days, and it has been for over a decade. :)
an0ther1 3-Dec-17 15:46pm    
Are you calling me old? Let me get my walking frame you whipper snapper :)
INSERT INTO tempWIPAeroV1 (WIPMATL,WIP_sold, RKey)
                (SELECT Material_cost ,Sold_cost,ISNULL(tempWIPAeroV1.RKEY,'') AS RKey  
                 FROM NewValues
                 LEFT JOIN tempWIPAeroV1 ON  (tempWIPAeroV1.RKEY = NewValues.RKEY) );
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900