I have two tables, each with serially increasing ID numbers. One is roughly a copy of the other. For my purposes, assume that the only two fields in each table are Instructor_name and ID. Some instructor names are blank, because they're derived from a text file that only lists the instructor name once. What I want to do is populate the blank rows with the instructor name that is "above" them, and I know what rows are above them by the ID number. Assume that rows with ID numbers 50 through 55 are blank, and that row 49 has the name of the instructor that should also appear in those rows. Row 56 has the name of a new instructor.
SO I thought a correlated subquery would be the way to go. This is what I've written so far:
UPDATE tmpAll703NonInstructorRows
AS T1
SET instructor_name =
(select instructor_name
FROM FACC703Refine1
WHERE (ltrim(instructor_name)>"A
") and id =
(select max(ID)
from FACC703Refine1
where (ltrim(instructor_name)>"A
") and ID < T1.ID))
The result of this is the dreaded "Operation must use an updateable query" result, and no updating. Can someone rewrite this to have it update each row of my tmp table with the instructor name of the row that appears above it? I do not wish to pursue a non-SQL solution now, but my other thought is to transfer the whole damn thing into Excel and run a macro on it to "fill down" the whole report.
By the way, the following, working with only one table, also does not run.
Update FACC703Refine1
Set Instructor_name =
(select instructor_name
from FACC703Refine1 f1
where instructor_name is not null
and ID =
(select max(ID)
from FACC703Refine1 F2
where ID < FACC703Refine1.ID)
)
Where instructor_name is null
Start Free Trial