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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Insert into a table from a temp table
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

43 Posts

Posted - 10/16/2012 :  09:45:41  Show Profile  Reply with Quote
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?

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 10/16/2012 :  09:53:20  Show Profile  Reply with Quote
you told update and what you gave is an insert code

as per your explanation it should be

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

Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000