Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting INSERT Error

Status
Not open for further replies.

Compkitty

Programmer
Jan 7, 2005
121
0
0
US
HERE IS MY INSERT STATEMENT

Code:
INSERT INTO Tbl_Temp_CDR(Bill_Duration)
SELECT TmpEgress.Egress_Seconds
FROM TmpEgress, Tbl_Temp_CDR T1
WHERE TmpEgress.Pkey = T1.CDR_Seq_Key

HERE IS THE ERROR

Code:
Server: Msg 515, Level 16, State 2, Line 1
Cannot insert the value NULL into column 'CDR_Seq_Key', table 'Traffic_1.dbo.Tbl_Temp_CDR'; column does not allow nulls. INSERT fails.
The statement has been terminated.

there is already data in the Table Tbl_Temp_CDR, I'm just wanting to insert the data from one table to another using the Pkey/CDR_Seq_Key as the matching...
I have tried UPDATE Table, but when I run the next set, it updates the previous sets values to NULL.
There is not NULLs in either the the tables (Pkey/CDR_Seq_Key) Fields.

Any help is appreciated by this newbie...
 
Looks like you need to add the primary key field...
Code:
INSERT INTO Tbl_Temp_CDR(CDR_Seq_Key, Bill_Duration)
SELECT TmpEgress.Pkey,TmpEgress.Egress_Seconds
FROM TmpEgress, Tbl_Temp_CDR T1
WHERE TmpEgress.Pkey = T1.CDR_Seq_Key

"...we both know I'm training to become a cagefighter...see what happens if you try 'n hit me..."
 
Why would I need to insert it??? OH... I see.. Well I'm not wanting ot (add rows) just update.. But I thought that I could INSERT Instead of UPDATE because my UPDATE was making all the other records NULL.... Is there another way to update one column w/ the data from another table...
 
so describe what you want to do in words, because if you need to update the table, then we shouldn't have the INSERT statement listed anywhere...

"...we both know I'm training to become a cagefighter...see what happens if you try 'n hit me..."
 
Try this:

Code:
UPDATE t2
SET Bill_Duration = t1.Egress_Seconds
FROM TmpEgress t1 JOIN Tbl_Temp_CDR t2 ON t1.Pkey = t2.CDR_Seq_Key

--James
 
Ok, I have a table that has 135 columns.. Well I am running stored Procedure that creates other tables and calculates my information.. Well both tables have PKs ( that are the same field/value) Well I want to update the table w/135 cols w/ this value into one of it's columns which currently is null.
The stored procedure runs several times (there are a lot of records to update and do calculations on ..)

IE.

TABLE1 (135 cols) Column 123 is null value since it's a calculated field pulled from another table.

TABLE2 (10 cols) Needs to update TABLE1 w/ it's Value in Col02

Both Tables COL001 is the PK and they are the same value...

 
Are you getting NULLs when you run only the following...? :
Code:
SELECT TmpEgress.Egress_Seconds
FROM TmpEgress, Tbl_Temp_CDR T1
WHERE TmpEgress.Pkey = T1.CDR_Seq_Key

"A long life is when each day is full and every hour wide!"
(A Jewish Mentor)
M. [hourglass]

 
JAMESLEAN - THANKS!!! This is seeeming to work... I will reupdate this post when/after I run the next batch... THANKS so much guys....
 
Compkitty,

Remember this....

INSERT - inserts rows
UPDATE - adds data or changes data in rows

-SQLBill

Posting advice: FAQ481-4875
 
That's What I Have always thought, but started grabbing at straws when my UPDATES weren't working...
THANKS
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top