I have the following SQL statement:
UPDATE tbl_Invoices
SET tbl_Invoices.Base = tbl_Bases.BasePrice
FROM tbl_Invoices
INNER JOIN tbl_Bases ON tbl_Bases.ProductNumber = tbl_Invoices.ProductNumber
AND tbl_Bases.ChangeOrderID = tbl_Invoices.ChangeOrderID
AND tbl_Bases.CustomerName = 'VALEO'
AND tbl_Bases.CountryCode = 'FR'
AND tbl_Bases.ContractYear = 0
Access keep telling me I have a syntax error (missing operator)
This drives me nuts. Can someone tell me what's wrong?
UPDATE ... FROM doesn't exist in Access SQL, here you do it like this:
UPDATE tbl_Invoices
INNER JOIN tbl_Bases ON tbl_Bases.ProductNumber = tbl_Invoices.ProductNumber
AND tbl_Bases.ChangeOrderID = tbl_Invoices.ChangeOrderID
AND tbl_Bases.CustomerName = 'VALEO'
AND tbl_Bases.CountryCode = 'FR'
AND tbl_Bases.ContractYear = 0
SET tbl_Invoices.Base = tbl_Bases.BasePrice
Thanks a lot.
I still have an error as the = 'VALEO' etc... are not allowed in Join but this is working if moved to a where clause:
UPDATE tbl_Invoices
INNER JOIN tbl_Bases ON tbl_Bases.ProductNumber = tbl_Invoices.ProductNumber
AND tbl_Bases.ChangeOrderID = tbl_Invoices.ChangeOrderID
SET tbl_Invoices.Base = tbl_Bases.BasePrice
WHERE tbl_Bases.CustomerName = 'VALEO'
AND tbl_Bases.CountryCode = 'FR'
AND tbl_Bases.ContractYear = 0
Related
Having a problem with the plugin DMSF in redmine I have found a link with a SQL query that could fix the issue, however I am using PostgreSQL and that query returns a syntax error directly on f.project_id.
The MySQL query is:
update dmsf_files f
set f.project_id = (select d.project_id from dmsf_folders d where d.id = f.dmsf_folder_id and d.system = 1)
where (select dmsf_folders.system from dmsf_folders where dmsf_folders.id = f.dmsf_folder_id) = 1;
What should be the PostgreSQL equivalent ?
I have found some online Database syntax translator but unfortunately with no success at all.
Remove the alias from the left side of the SET clause:
update dmsf_files f
set project_id = (select d.project_id from dmsf_folders d
where d.id = f.dmsf_folder_id and d.system = 1)
where (select dmsf_folders.system from dmsf_folders
where dmsf_folders.id = f.dmsf_folder_id) = 1;
I’m trying to update a table that is joined with another one to update the right record.
Here is my command so far:
UPDATE
links l
SET
l.l_id = `[value-1]`,
l.l_facebook = `[value-2]`,
l.l_youtube = `[value-3]`,
l.l_twitter = `[value-4]`,
l.l_googleplus = `[value-5]`,
l.l_rss = `[value-6]`,
l.l_homepage = `[value-7]`,
l.l_freigegeben = `[value-8]`
JOIN
sponsering ON l.l_id = sponsering.links_l_id
WHERE
sponsering.s_userID = 2
Trying to run the command in phpmyadmin gives me the following error message:
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use
near 'JOIN sponsering ON l.l_id = sponsering.links_l_id WHERE
sponsering.s_user' at line 12
I need to join the table sponsering because this gives me the correct record in the links table.
How can I solve this?
Try this
UPDATE
links l,
sponsering s
SET
l.l_faceook = `[value-2]`,
l.l_youtube = `[value-3]`,
l.l_twitter = `[value-4]`,
l.l_googleplus = `[value-5]`,
l.l_rss = `[value-6]`,
l.l_homepage = `[value-7]`,
l.l_freigegeben = `[value-8]`
WHERE
l.l_id = s.links_l_id AND
sponsering.s_userID = 2
In MySQL, the join is part of the update statement itself. There is no separate from:
UPDATE links l JOIN
sponsering s
ON l.l_id = s.links_l_id
SET
l.l_id = `[value-1]`,
l.l_faceook = `[value-2]`,
l.l_youtube = `[value-3]`,
l.l_twitter = `[value-4]`,
l.l_googleplus = `[value-5]`,
l.l_rss = `[value-6]`,
l.l_homepage = `[value-7]`,
l.l_freigegeben = `[value-8]`
WHERE s.s_userID = 2;
Some other databases use a FROM clause for the same purpose.
I need to update a table and this is my sql code so far but i'm getting the following error message:
Line 30: Incorrect syntax near ')'.
UPDATE dbo.Part
SET SupplierShortName = NationalSupplier.ShortName,
SupplierLongName = NationalSupplier.LongName
SELECT *
FROM dbo.Part
JOIN dbo.NationalSupplier
ON Part.SupplierNumber = NationalSupplier.Number
AND (ISNULL(Part.SupplierShortName,'') <> ISNULL(NationalSupplier.ShortName,'')
OR ISNULL(Part.SupplierLongName,'') <> ISNULL(NationalSupplier.LongName,''))
LEFT OUTER JOIN dbo.NationalPart
ON Part.NationalPartID = NationalPart.NationalPartID
WHERE Part.DWCreationEntityID = 1
AND NationalPart.NationalPartID is NULL
Thanks in advance for any valuable tips !
Try this:
UPDATE dbo.Part
SET SupplierShortName = NationalSupplier.ShortName,
SupplierLongName = NationalSupplier.LongName
FROM dbo.Part
JOIN dbo.NationalSupplier
ON Part.SupplierNumber = NationalSupplier.Number
AND (ISNULL(Part.SupplierShortName,'') <> ISNULL(NationalSupplier.ShortName,'')
OR ISNULL(Part.SupplierLongName,'') <> ISNULL(NationalSupplier.LongName,''))
LEFT OUTER JOIN dbo.NationalPart
ON Part.NationalPartID = NationalPart.NationalPartID
WHERE Part.DWCreationEntityID = 1
AND NationalPart.NationalPartID is NULL
You should alias the table names to make things concise.
Hello i'm trying to make an update with a select statement.
Here is my code
update recolha_hrs_2014 r set r.state = 'porval' from (select e.sigla
from dgrhe_entidade e) where r.state = 'finalizado' and r.qzp = '10'
and e.sigla = '145014'
However it gives me an error.
ERROR: subquery in FROM must have an alias
LINE 3: from (select e.sigla from dgrhe_entidade e)
Any suggestion. What am i doing wrong?
Hope you can help me
Thanks,
Try this:
update r
set set r.state = 'porval'
from recolha_hrs_2014 r
inner join dgrhe_entidade e on e.??? = r.????
where r.state = 'finalizado' and r.qzp = '10' and e.sigla = '145014'
I'm not sure which field(s) in dgrhe_entidade map to recolha_hrs_2014, but that's what needs to go in: "e.??? = r.????"
Can anyone tell me what is wrong with this Query ?
UPDATE
violetta.navi__stop
SET
violetta.navi__stop.endHour = VB.endHour
FROM
violetta.navi__stop AS V
INNER JOIN
violetta_back.navi__stop AS VB
ON V.code = VB.code
This code sample works for me on my database:
SELECT
V.code, V.endHour
FROM
violetta.navi__stop AS V
UNIQUE
violetta_back.navi__stop AS VB
ON V.code = VB.code
Try this instead:
UPDATE
violetta.navi__stop v
INNER JOIN
violetta_back.navi__stop AS VB
ON V.code = VB.code
SET
v.endHour = VB.endHour