0
votes

I'm trying to update the table with inner join using VBA in MS Access but I've tested the SQL Update statement in SQL Server Management Studio and it's working. I'm getting an error as a result, see below.

Appreciate any help.

SQL = "Update A set A.RevBillCtrl = 8 from dbo_tblMain A inner join dbo_tblPlateNo as B ON B.PNC = A.PLC inner join dbo_tblSubcons as C on B.SCC = C.SCC "

enter image description here

2
What data type is A.RevBillCtrl? - Ken White
Data type of A.RevBillCtrl is integer. - RedHat

2 Answers

1
votes

In Access the Update with joins has a different syntax comparing to SQL Server. The correct syntax will be:

Update dbo_tblMain AS A 
inner join dbo_tblPlateNo as B on B.PNC = A.PLC 
inner join dbo_tblSubcons as C on B.SCC = C.SCC
set A.RevBillCtrl = 8 

BTW, earlier Access versions did not like the INNER JOINS that follow one after another. They used a nested joins syntax:

Update dbo_tblMain AS A 
inner join (dbo_tblPlateNo as B
  inner join (dbo_tblSubcons as C 
  on B.SCC = C.SCC)
on B.PNC = A.PLC)
set A.RevBillCtrl = 8 
0
votes

The idea basically is that you have to do the JOINs in a nested way. See below correct one.

Sql = "UPDATE dbo_tblMain
      INNER JOIN (dbo_tblPlateNo 
       INNER JOIN dbo_tblSubCons 
       ON (dbo_tblPlateNo.SCC = dbo_tblSubCons.SCC)) 
      ON (dbo_tblMain.PLC = dbo_tblPlateNo.PNC) 
      SET dbo_tblMain.RevBillCtrl = 8"