Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Insert into a table from a temp table

Author  Topic 

jpost
Starting Member

43 Posts

Posted - 2012-10-16 : 09:45:41
I am trying to update values in a table called POS from a temp table that I created. I want to update the eligibility field in the POS table with the value in the status column from the temp table.I have to join the temp table with the student table because there isn't a student number listed in the POS table. Here is my code:

INSERT INTO POSEligibility (eligibility)
select tt.Status
FROM TempTestTable tt
join Student s on tt.StudentID = s.studentNumber
join POSEligibility pe on s.personID = pe.personID

When I run this code I get the error that states
Cannot insert the value NULL into column 'personID', table 'pickerington_sandbox.dbo.POSEligibility'; column does not allow nulls. INSERT fails.
The statement has been terminated.

I added a where clause to narrow my insert down to just one student and still got the same error. Any suggestions?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-10-16 : 09:53:20
you told update and what you gave is an insert code

as per your explanation it should be


UPDATE p
SET p.eligibility= t.Status
FROM POSEligibility p
Inner join Student s
ON s.personID = p.personID
INNER JOIN temptesttable t
on t.StudentID = s.studentNumber


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -