Link to home
Start Free TrialLog in
Avatar of Aaron Greene
Aaron GreeneFlag for United States of America

asked on

UPDATE SQL Statement

I have a table that has been put together from several sources of data.  Not all of the data in the original tables was complete.  I need to go in and update the missing data.  For example, I have the meter serial number in some records and not others.  I need to populate the incomplete records with the data from the "good data".  

I've created a view of the table to select the rows where METER_SERIAL is populated.
SELECT     ACCOUNT_ID, METER_SIZE
FROM         dbo.vData_CurrentMonth
WHERE     (NOT (METER_SIZE IS NULL))

I want to update tblData with the METER_SIZE data where the ACCOUNT_ID fields are equal.
ASKER CERTIFIED SOLUTION
Avatar of Aneesh
Aneesh
Flag of Canada 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
hi AaronGreene1906,

Try
UPDATE D
SET METER_SIZE=C.METER_SIZE
FROM tblData D INNER JOIN
     dbo.vData_CurrentMonth C ON D.ACCOUNT_ID=C.ACCOUNT_ID
WHERE D.METER_SIZE IS NULL AND C.METER_SIZE IS NOT NULL

Open in new window

hi AaronGreene1906,

Try
UPDATE D
SET METER_SIZE=C.METER_SIZE
FROM tblData D INNER JOIN
     dbo.vData_CurrentMonth C ON D.ACCOUNT_ID=C.ACCOUNT_ID
WHERE D.METER_SIZE IS NULL AND C.METER_SIZE IS NOT NULL

Open in new window