Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

UPDATE with SELECT subquery: How to avoid nulls 1

Status
Not open for further replies.

thermidor

Programmer
Nov 28, 2001
123
US
All:

I have an UPDATE statement that uses a SELECT subquery:
UPDATE L_BUDGET bud
SET bud.acct_unit =
(SELECT Xref.NEWCENTER
FROM L_CROSS_REF Xref
WHERE ... );

However, in cases where there is no match, the UPDATE sets the field to null. I need the UPDATE to not modify the data where there is no match.

Probably this has been asked before, but I can 't think of how to search for it. I'd appreciate any help.

TIA,
Sven
 
Try this:
Code:
UPDATE L_BUDGET bud            
  SET bud.acct_unit = 
    (SELECT Xref.NEWCENTER
      FROM L_CROSS_REF Xref  
        WHERE ... )
  WHERE EXISTS 
    (SELECT 1
      FROM L_CROSS_REF Xref    
        WHERE ... );
[3eyes]


----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top