I am getting the following error message when attempting to save or run a SQL query in MS Access 2016:
"Syntax error (missing operator) in query expression 'M.ScheduleKey FROM Actual_Data A'
The Query is:
UPDATE Actual_Data
SET A.ScheduleKey = M.ScheduleKey
FROM Actual_Data A, Match M
WHERE A.ActualKey = M.ActualKey
Both the ScheduleKey & ActualKey fields are text fields.
Any help on resolving this would be greatly appreciated.
You can use this instead:
UPDATE Actual_Data A
INNER JOIN Match M
ON A.ActualKey = M.ActualKey
SET A.ScheduleKey = M.ScheduleKey
Related
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
I have the following query that works great and shows me where the tbl_staff.staff_id and tbl_lead.rlog_create_user_id values do not match.
SELECT
tbl_staff.staff_id,
tbl_staff.username,
tbl_lead.rlog_create_user_name,
tbl_lead.rlog_create_user_id
FROM
tbl_staff
JOIN tbl_lead ON tbl_staff.username = tbl_lead.rlog_create_user_name
AND tbl_staff.staff_id <> tbl_lead.rlog_create_user_id;
The query returns values like this where you can see the 1014 does not match the 1004.
1014 bubba bubba 1004
I want to update the value in the tbl_lead.rlog_create_user_id to the same value as is found in tbl_staff.staff_id.
I tried to insert a SET command but it's giving me a generic syntax error:
SELECT
tbl_staff.staff_id,
tbl_staff.username,
tbl_lead.rlog_create_user_name,
tbl_lead.rlog_create_user_id
FROM
tbl_staff
JOIN tbl_lead ON tbl_staff.username = tbl_lead.rlog_create_user_name
AND tbl_staff.staff_id <> tbl_lead.rlog_create_user_id
SET tbl_lead.rlog_create_user_id=tbl_staff.staff_id ;
The actual error is:
[Err] 1064 - You have an error in your SQL syntax; check the manual
that corresponds to your MySQL server version for the right syntax to
use near 'SET tbl_lead.rlog_create_user_id=tbl_staff.staff_id' at line
10
I tried to change the SELECT to and UPDATE command using this question but still could not get it working: How can I do an UPDATE statement with JOIN in SQL?
Try this
UPDATE tbl_lead
JOIN tbl_staff ON tbl_staff.username = tbl_lead.rlog_create_user_name
SET tbl_lead.rlog_create_user_id = tbl_staff.staff_id
WHERE tbl_staff.staff_id <> tbl_lead.rlog_create_user_id;
Have you tried like this ?
UPDATE tbl_staff, tbl_lead
SET tbl_lead.rlog_create_user_id = tbl_staff.staff_id
WHERE tbl_staff.username = tbl_lead.rlog_create_user_name
I intend to do:
EXECUTE('UPDATE tableA SET campaignkey = ''20170101'' where storekey = 16
and campaignkey LIKE ''%,%''') at MYLINKEDSERVER
but I get the error that:
You have an error in your SQL syntax; [...] for the right syntax to use near 'where storekey = 16 and campaignkey LIKE '%,%''
Does anyone have any idea what is wrong? To me it seems like I might have one ' too many on my LIKE statement, but I have Always used '' to indicate a non-numeric value. I don't want to fiddle with this to prevent updating far too many values on this server.
campaignkey is non-numeric (I Believe varchar) and storekey is integer.
Edit
I must not use OPENQUERY() because it is not set up correctly, and this is a urgent update.
Edit 2
Seems like it is because of apostrophes 's in the EXECUTE statement.
When I conduct:
select * from openquery(linkedserver,'Select * from tableA where storekey = 16
and campaignkey = ''20170826,151''')
it works, but when using:
EXECUTE('Select * from tableA where storekey = 16
and campaignkey = ''20170826,151''') at linkedserver
I get the error that I need to check the manual by the where clause. From googling it appears however that the correct syntax in fact is:
EXECUTE('UPDATE TableX SET StringVar = ''stringValue'' WHERE intVar = 3
AND stringVar = ''xxxxx''') AT LinkedServer
I don't know why this won't work for me.. I have tried many combinations of '', '" etc.
What about this one?
update openquery(linkedserver,'Select * from tableA where storekey = 16
and campaignkey = ''20170826,151''')
set campaignkey = '20170101'
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.
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