Link to home
Start Free TrialLog in
Avatar of armgon
armgonFlag for United States of America

asked on

SQL Update Statement with Multiple Selects

I get the following message from SQL Server 2008:
"Msg 515, Level 16, State 2, Line 1
Cannot insert the value NULL into column 'PrimVendID', table 'bzbapp.dbo.ItemSite'; column does not allow nulls. UPDATE fails.
The statement has been terminated."

When I run the following Query:
UPDATE
ITEMSITE

SET
ITEMSITE.PRIMVENDID=
(SELECT  TOP 1 POTran.vendid
FROM POTran
where POTRAN.invtid = ITEMSITE.INVTID
AND POTran.trandate>='06/23/2010'
ORDER BY POTran.PONbr DESC)

WHERE
ITEMSITE.SITEID='WEST'
AND itemsite.invtid in (Select itemsite.invtid from itemsite where itemsite.siteid='WEST' and itemsite.moveclass='A')

I am trying to update the itemsite table's PRIMVENDID utilizing the  POTRAN tables most recent record VENDID field.

Your input on how to format this QUERY would be greatly appreciated. I cannot seem to figure out how I am picking up a null value.
ASKER CERTIFIED SOLUTION
Avatar of Rajkumar Gs
Rajkumar Gs
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Guy Hengel [angelIII / a3]
would this article help you writing your UPDATE with JOINs?
https://www.experts-exchange.com/A_1517.html