SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

jpost
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?

visakh16
Very Important crosS Applying yaK Herder

India
52309 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


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
  Previous Topic Topic Next Topic  
 New 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.03 seconds. Powered By: Snitz Forums 2000