Advertisement

04.02.2008 at 09:18AM PDT, ID: 23289873
[x]
Attachment Details

Update Access table via SQL from other table on non-equijoin

Asked by thomas_m_schmidt in SQL Query Syntax, Microsoft Access Database

Tags: Microsoft, Access, 2003, SQL Update Query

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 nullStart Free Trial
[+][-]04.02.2008 at 10:21AM PDT, ID: 21265222

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.02.2008 at 10:24AM PDT, ID: 21265243

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: SQL Query Syntax, Microsoft Access Database
Tags: Microsoft, Access, 2003, SQL Update Query
Sign Up Now!
Solution Provided By: aflockhart
Participating Experts: 2
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628