Solved

Update Join Query Cannot insert Null

Posted on 2007-12-02
5
287 Views
Last Modified: 2010-05-18
I'm trying to update a particular table with contents from another table but keep getting an error.

UPDATE Cogsdale
SET Cogsdale.ADDRESS1 = Cleaned.Address1, Cogsdale.ADDRESS2 = Cleaned.Address2,
Cogsdale.umCityName = Cleaned.City, Cogsdale.State = Cleaned.State, Cogsdale.umZipCode = Cleaned.Zip
FROM UMRM0112 Cogsdale INNER JOIN RP_CleanAddresses Cleaned
ON Cogsdale.umAddressCode = Cleaned.AddressCode  

I get:
Server: Msg 515, Level 16, State 2, Line 1
Cannot insert the value NULL into column 'STATE', table 'test.dbo.UMRM0112'; column does not allow nulls. UPDATE fails.
The statement has been terminated.

I don't see any nulls in the State field...
0
Comment
Question by:Rayzback
  • 3
5 Comments
 
LVL 25

Expert Comment

by:imitchie
ID: 20392849
Can you recheck the Cleaned table?
0
 
LVL 25

Expert Comment

by:imitchie
ID: 20392855
try this query

SELECT Cleaned.AddressCode, Cleaned.State
FROM UMRM0112 Cogsdale
INNER JOIN RP_CleanAddresses Cleaned ON Cogsdale.umAddressCode = Cleaned.AddressCode
ORDER BY 2

The nulls should show up at the bottom (or top)
0
 
LVL 1

Author Comment

by:Rayzback
ID: 20392945
Argggg I do... WHERE State = NULL returned nothing?

Can I replace the nulls with ' '?
0
 
LVL 25

Accepted Solution

by:
imitchie earned 500 total points
ID: 20392954
You CANNOT test for NULL using =.
Use
WHERE State IS NULL

as for your query, use

UPDATE Cogsdale
SET Cogsdale.ADDRESS1 = Cleaned.Address1, Cogsdale.ADDRESS2 = Cleaned.Address2,
Cogsdale.umCityName = Cleaned.City, Cogsdale.State = IsNull(Cleaned.State, ''), Cogsdale.umZipCode = Cleaned.Zip
FROM UMRM0112 Cogsdale INNER JOIN RP_CleanAddresses Cleaned
ON Cogsdale.umAddressCode = Cleaned.AddressCode  
0
 
LVL 10

Expert Comment

by:LennyGray
ID: 20393338
Change the property of the data element STATE to allow nulls.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question