Update query

AnnPhil

Registered User.
Local time
Today, 13:05
Joined
Dec 18, 2001
Messages
246
Is it possible to create an update query that will only update fields if there is data in it? For example i have a temp table with several fields, i want to build one query that would look at a row in the temp table and update those that have data in them to another table. Right now my update query updates the fields with data correctly but if there is not data in one or more fields from the temp table, those fields get updated to blanks in the other table which wipes out the exiting data that i wanted to keep.

Hope this make sense,
 
Normally an update from one table to another is done using a join. In that case, use a WHERE clause indicating that you only want non-blank records. A blank record could possibly mean a Null record or, in some cases, a record with a zero-length string.

UPDATE Customers AS C
INNER JOIN tempTable as T
ON T.CustID = C.CustID
SET C.LastName = T.LastName,
C.FirstName = T.FirstName
WHERE NOT T.LastName IS NULL

or perhaps

WHERE NOT LEN(T.LastName & "") = 0
 
Last edited:

Users who are viewing this thread

Back
Top Bottom