How to resolve MS Access SQL UPDATE syntax error - ms-access

I am trying to type a SQL query in MS Access to update the records in FilesTable.FilePath with the records in Files.FPath, when the FilesTable.FileName Matches a record in Files.FName, but I receive an error:
UPDATE FilesTable
SET FilesTable.[FilePath] = Files.[FPath]
FROM (FilesTable INNER JOIN Files ON (FilesTable.[FileName] = Files.[FName])
WHERE *;
syntax error (missing operator) in query expression 'Files.[FPath]
FROM (FilesTable INNER JOIN Files ON (FilesTable.[FileName] = Files.[FName])
WHERE *;'
I have also tried to add () after Set as well which results in an error as well:
UPDATE FilesTable
SET (FilesTable.[FilePath] = Files.[FPath])
FROM (FilesTable INNER JOIN Files ON (FilesTable.[FileName] = Files.[FName])
WHERE *;
Syntax Error in UPDATE Statement.
Here is how my tables looks like

This is the correct query:
UPDATE FilesTable
INNER JOIN Files ON (FilesTable.FileName = Files.FName)
SET FilesTable.FilePath = Files.FPath

Related

SSIS Execute SQL Task error

I'm having an SSIS package which gives the following error when executed :
Error: 0xC002F210 at Execute SQL Task 1, Execute SQL Task: Executing the query "Declare #POID as Varchar(50)
Set #POID = 636268
..." failed with the following error: "Unable to populate result columns for single row result type. The query returned an empty result set.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
Task failed: Execute SQL Task 1
The package has a single Execute SQL task with the properties listed below :
General Properties
Result Set : Single Row
ConnectionType : OLEDB
Connection : Connected to Server
SQLSourceType : Direct Input
SQL Statement :
Declare #POID as Varchar(50)
Set #POID = 0
SELECT DISTINCT BizTalk_POA_HEADER.PONUMBER, FAN_Suppliers.SupplierName, FAN_Company_Details.CompanyName, FAN_Company_Details.[PrimaryEmail], BizTalk_POA_HEADER.[DeliveryDate]
FROM BizTalk_POA_HEADER
INNER JOIN FAN_PO_Details ON BizTalk_POA_HEADER.PONUMBER = FAN_PO_Details.PoNumber
INNER JOIN FAN_PO ON FAN_PO_Details.PurchaseOrderID = FAN_PO.PurchaseOrderID
INNER JOIN FAN_SupplierDetails ON FAN_PO.SupplierDetailsID = FAN_SupplierDetails.SuppliersDetailsID
INNER JOIN FAN_Suppliers ON FAN_SupplierDetails.SupplierID = FAN_Suppliers.SupplierID
INNER JOIN FAN_Company_Details ON FAN_PO.CompanyID = FAN_Company_Details.CompanyDetailsID
WHERE (BizTalk_POA_HEADER.PONUMBER = #POID)**
IsQueryStorePro : False
BypassPrepare : False
Parameter Mapping Properties
None
ResultSet
ResultName Variable Name
0 User:PONUMBER
1 User:StoreName
2 User:StoreEmail
3 User:Supplier
4 User:DeliveryDate
I would appreciate if anybody can help me out of this issue by suggeting where the problem is.
I then changed my query to the following as the above was showing conversion error in SSMS, when I try to include the below in Execute SQL Task the query isn't saved , any reason?
SELECT DISTINCT BizTalk_POA_HEADER.PONUMBER,FAN_Suppliers.SupplierName, FAN_Company_Details.CompanyName,
FAN_Company_Details.[PrimaryEmail], BizTalk_POA_HEADER.[DeliveryDate]
FROM BizTalk_POA_HEADER INNER JOIN
FAN_PO_Details ON CAST(BizTalk_POA_HEADER.PONUMBER AS VARCHAR(128)) = CAST(FAN_PO_Details.PoNumber AS VARCHAR(128)) INNER JOIN
FAN_PO ON FAN_PO_Details.PurchaseOrderID = FAN_PO.PurchaseOrderID INNER JOIN
FAN_SupplierDetails ON FAN_PO.SupplierDetailsID = FAN_SupplierDetails.SuppliersDetailsID INNER JOIN
FAN_Suppliers ON FAN_SupplierDetails.SupplierID = FAN_Suppliers.SupplierID INNER JOIN
FAN_Company_Details ON FAN_PO.CompanyID = FAN_Company_Details.CompanyDetailsID
Thanks in Advance.
If 0 records are returned from your query and you are trying to populate a result set, that is the error you will get. Change your query so it always returns a single result and the error will go away.

Update table in MS Access from views exported from SQL

I have created a table and need to update the entries by comparing the data from the view that I have created in SQL server
This action need to performed by a button click in MS Access forms
I have written the following query in MS Access - Query. Exported the view totaltemp1 from sql server.
update P_Payroll as p
inner join totaltemp1 as tp on p.emp_id = tp.emp_id
inner join P_Student_Supervisor as ss on tp.emp_id = ss.emp_id
set Number_of_Hours = tp.temp_drop_hours,
Total_Payment = tp.temp_drop_hours*ss.emp_hourlywage
where p.emp_id = tp.emp_id and ss.emp_id = p.emp_id;
Previously I got this working correctly in SQL server in stand alone mode. Code for that as follows.
update P_Payroll set Number_of_Hours = tp.temp_drop_hours, Total_Payment = tp.temp_drop_hours*ss.emp_hourlywage
from totaltemp1 as tp, P_Payroll as p, P_Student_Supervisor as ss
where p.emp_id = tp.emp_id and ss.emp_id = p.emp_id;
I have checked the data structure too. I am just getting an error
"Syntax error (missing operator) in query expression 'p.emp_id = tp.emp_id inner join P_Student_Supervisor as ss on tp.emp_id = ss.emp_i"
Thanks for your time
Pk.
Two things you can check... first, remove the WHERE clause - you're already specifying those conditions in the JOIN statements.
Then, put brackets around your joins...
UPDATE (P_Payroll AS p
INNER JOIN totaltemp1 AS tp on p.emp_id = tp.emp_id)
INNER JOIN P_Student_Supervisor AS ss on tp.emp_id = ss.emp_id
SET p.Number_of_Hours = tp.temp_drop_hours,
p.Total_Payment = tp.temp_drop_hours * ss.emp_hourlywage
Access like brackets...

syntax error when running query in MS Access 2010

good day
i am trying to run an update query but getting the following error "syntax error in join operation"
Here is the query:
update (table 1
set SEQ=table2.SEQ)
from (table1 inner join table2 on table1.NBR=table2.NBR and table1.LINE = table2.LINE and table1.VENNO = table2.VENNO and table1.INVNO = table2.INVNO where table1.SEQ <> table2.seq)
Any assistance will be appreciated.
Your syntax is wrong. UPDATE queries don't use FROM. The right syntax is:
update
table1
inner join table2
on table1.NBR=table2.NBR
and table1.LINE = table2.LINE
and table1.VENNO = table2.VENNO
and table1.INVNO = table2.INVNO
set
table1.SEQ = table2.SEQ
where
table1.SEQ <> table2.seq

Update Query Issues

Here is my update query.
UPDATE sugarcrm.qb_salesorders_leads_c, sugarcrm.qb_salesorders
SET sugarcrm.qb_salesorders_leads_c.qb_salesorders_leadsleads_ida = sugarcrm.qb_salesorders.memo, sugarcrm.qb_salesorders_leads_c.qb_salesorders_leadsqb_salesorders_idb = sugarcrm.qb_salesorders.id
WHERE sugarcrm.qb_salesorders.id = sugarcrm.qb_salesorders_leads_c.qb_salesorders_leadsqb_salesorders_idb
When I run this it gives me Affected rows 0.
Here is my select statement using the same info that is in the WHERE statement.
SELECT * from qb_salesorders_leads_c, sugarcrm.qb_salesorders
WHERE sugarcrm.qb_salesorders_leads_c.qb_salesorders_leadsqb_salesorders_idb = sugarcrm.qb_salesorders.id
This returns 354 Rows which is what I am expecting to update on the update query. What am I missing. Please help!
Convert the implicit join to an explicit one:
UPDATE sugarcrm.qb_salesorders_leads_c leads
INNER JOIN sugarcrm.qb_salesorders orders
ON orders.id = leads.qb_salesorders_leadsqb_salesorders_idb
SET leads.qb_salesorders_leadsleads_ida = orders.memo,
leads.qb_salesorders_leadsqb_salesorders_idb = orders.id
As you can see, I also used aliases to make the SQL compact and legible.
To UPDATE using a join, you have to use the explicit join syntax:
UPDATE sugarcrm.qb_salesorders_leads_c
INNER JOIN sugarcrm.qb_salesorders
ON qb_salesorders_leadsqb_salesorders_idb.id
= sugarcrm.qb_salesorders_leads_c.qb_salesorders_leadsqb_salesorders_idb
SET sugarcrm.qb_salesorders_leads_c.qb_salesorders_leadsleads_ida
= qb_salesorders_leadsqb_salesorders_idb.memo
, sugarcrm.qb_salesorders_leads_c.qb_salesorders_leadsqb_salesorders_idb
= sugarcrm.qb_salesorders.id

Update a single table based on multiple tables - appears to works MySql not ACCESS 2003

Mysql Version Works
UPDATE results SET rCARRIER = (
SELECT cellCarrierName
FROM tblImportedTempTable, user, cellCarrier
WHERE
userEmployeeNumber = tblImportedTempTable.EMPLOYEENUMBER
AND userId = results.rUserId
AND results.rPHONENUMBER = tblImportedTempTable.PHONENUMBER
AND CARRIER = cellCarrierId )
I have written this sql that works fine in MySql(above) and fails in access 2003(below) any suggestions? Is one or both of the 2 nonstandard sql? Does Access hav an admin problem?
Sorry the field and table names are diferent this is the ACCESS version.
Access version
UPDATE tblWorkerPhoneNumber SET tblWorkerPhoneNumber.PhoneCarrier = (
SELECT PhoneCarrierType.CarrierName
FROM tblImportedPhoneCarrier, tblWorkerMaster, PhoneCarrierType
WHERE
tblWorkerMaster.EmployeeNumber = tblImportedPhoneCarrier.Emp
AND tblWorkerMaster.WorkerID = tblWorkerPhoneNumber.WorkerID
AND tblWorkerPhoneNumber.PhoneNumber = tblImportedPhoneCarrier.Cell
AND tblImportedPhoneCarrier.CarrierCode = PhoneCarrierType.CarrierID )
Error Message
Operation must use and updateable query
Thanks
In MS Access, something like this:
UPDATE tblWorkerPhoneNumber
INNER JOIN tblWorkerMaster ON tblWorkerMaster.WorkerID = tblWorkerPhoneNumber.WorkerID
INNER JOIN tblImportedPhoneCarrier ON tblWorkerPhoneNumber.PhoneNumber = tblImportedPhoneCarrier.Cell
INNER JOIN PhoneCarrierType ON tblImportedPhoneCarrier.CarrierCode = PhoneCarrierType.CarrierID
SET tblWorkerPhoneNumber.PhoneCarrier = PhoneCarrierType.CarrierName
WHERE tblWorkerMaster.EmployeeNumber = tblImportedPhoneCarrier.Emp
(Might need to change the join conditions; I'm not familiar with your schema)