Solved

Update Join Query Cannot insert Null

Posted on 2007-12-02
5
297 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
New and Previous Values in a Query 7 36
Optimize the query 5 55
TSQL Challenge... 7 45
Get data from two MySQL tables 6 28
In database programming, custom sort order seems to be necessary quite often, at least in my experience and time here at EE. Within the realm of custom sorting is the sorting of numbers and text independently (i.e., treating the numbers as number…
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
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…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

730 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