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.
Microsoft SQL Server 2005

Avatar of undefined
Last Comment
Thomasian

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Aneesh

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Thomasian

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

Thomasian

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

Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes