I defined sql query and it runs with no problem on MySQL (I am using MySQL) , but when I am trying to execute it on client site (they uses SQL Server)
I am getting "Error: Incorrect syntax near 'si'." error message
Hope someone can help me to define right syntax.
The query is following:
update stepinstance si
inner join cesteplink l on si.id = l.stepinstance_id
inner join prompt p on si.prompt_id = p.id
set si.principal_id = 29160180
where l.case_id = 29179541
and si.principal_id = 1799409
and si.status = 'In Progress'
set has to be before the join conditions.
update si
set si.principal_id = 29160180
from stepinstance si
inner join cesteplink l on si.id = l.stepinstance_id
inner join prompt p on si.prompt_id = p.id
where l.case_id = 29179541
and si.principal_id = 1799409
and si.status = 'In Progress'
Related
I am trying to get a resulting column of the initial month an ID was created where multiple table JOINs are needed in MySQL Workbench.
SET #in_month = '0';
SELECT
ca.id
FROM capital.user ca
JOIN
capital.user_account cd on ca.id = cd.user_id
JOIN
capital.transaction ct on cd.user_id = ct.user_account_id
JOIN
capital.transaction_event ce on ct.id = ce.auth_entry_id
#in_month = month(ce.created) WHERE ce.message = 'Approved'
Group by id;
I get Syntax error: '#in_month' (at text suffix) is not valid input at this position on line 17, any ideas of what I might be doing wrong? I don't have a lot of experience with SQL
you are missing semicolon after variable declaration & and on join condition
SET #in_month = '0';
SELECT
ca.id
FROM capital.user ca
JOIN capital.user_account cd on ca.id = cd.user_id
JOIN capital.transaction ct on cd.user_id = ct.user_account_id
JOIN capital.transaction_event ce on ct.id = ce.auth_entry_id and
#in_month = month(ce.created)
WHERE ce.message = 'Approved'
Group by id;
UPDATE DFEntryValues
SET DFEntryValues.DFFieldvalue = NOW()
FROM DFEntryValues
JOIN DFEntries ON DFEntryValues.DFEntryID = DFEntries.DFEntryID
JOIN DynamicFormStructures ON DFEntries.DynamicFormStructureID = DynamicFormStructures.DynamicFormStructureID
JOIN Projects ON DynamicFormStructures.ProjectID = Projects.ProjectId
JOIN Clients ON Projects.ClientID = Clients.ClientID
JOIN DFFieldDefinition ON DFEntryValues.DFFieldDefinitionID = DFFieldDefinition.DFFieldDefinitionID
WHERE Clients.ClientID = '26' AND DFFieldDefinition.label = 'Geboortedatum';
I get the following error:
Error Code: 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 'WHERE Clients.ClientID = '26' AND DFFieldDefinition.label = 'Geboortedatum' SET' at line 12
Can someone point me out what's wrong with this query?
Kind regards!!
It seems you are not using correct format.
Hope this helps.
UPDATE DFEntryValues JOIN DFEntries ON DFEntryValues.DFEntryID = DFEntries.DFEntryID
JOIN DynamicFormStructures ON DFEntries.DynamicFormStructureID = DynamicFormStructures.DynamicFormStructureID
JOIN Projects ON DynamicFormStructures.ProjectID = Projects.ProjectId
JOIN Clients ON Projects.ClientID = Clients.ClientID
JOIN DFFieldDefinition ON DFEntryValues.DFFieldDefinitionID = DFFieldDefinition.DFFieldDefinitionID
SET DFEntryValues.DFFieldvalue = NOW()
WHERE Clients.ClientID = '26' AND DFFieldDefinition.label = 'Geboortedatum';
When I try the following query :
UPDATE cache_implementation
SET parent_through_compared_id = ncp.nid, parent_through_feature_id = nfp.nid
FROM cache_implementation n
INNER JOIN cache_compare nc ON n.compared_id = nc.nid
INNER JOIN cache_implementation ncp ON (nc.nid = ncp.compared_id AND n.feature_id = ncp.feature_id)
INNER JOIN cache_feature nf ON n.feature_id = nf.nid
INNER JOIN cache_implementation nfp ON (nf.nid = nfp.feature_id AND n.compared_id = nfp.compared_id)
I have the following error :
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 'FROM cache_implementation n INNER JOIN cache_compare nc ON n.compared_id = nc' at line 3
Through this query, I try to update two fields with value located in some other table, by making a mass update query.
You are using used in TSQL. Here's for MySQL.
UPDATE cache_implementation n
INNER JOIN cache_compare nc
ON n.compared_id = nc.nid
INNER JOIN cache_implementation ncp
ON (nc.nid = ncp.compared_id AND n.feature_id = ncp.feature_id)
INNER JOIN cache_feature nf
ON n.feature_id = nf.nid
INNER JOIN cache_implementation nfp
ON (nf.nid = nfp.feature_id AND n.compared_id = nfp.compared_id)
SET parent_through_compared_id = ncp.nid, parent_through_feature_id = nfp.nid
In MySQL multi-table update statement, the SET clause follows the table references. (This differs from the syntax used in other databases.)
To fix your statement, delete that first line, move the line with SET to the bottom, qualify the column references with the table alias, and change FROM to UPDATE. Voila.
UPDATEcache_implementation
FROM cache_implementation n
INNER JOIN ...
INNER JOIN ...
SET n.col = expr, n.col2 = expr
Multi-table update syntax documented here: http://dev.mysql.com/doc/refman/5.5/en/update.html
I am trying to update a field value in a mysql database using a select query with inner join
I currently get
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 'AS cc WHERE cc.account_id = na.account_id' at line 5
UPDATE accounts AS na
SET na.pdm_id = (
SELECT cp.person_id FROM `temp_accounts` AS ta INNER JOIN call_managment_system.accounts AS a ON ta.company_code = a.company_code
INNER JOIN contact_personal AS cp ON cp.name = ta.FSM AND contact_link = 'PDM'
)
WHERE a.account_id = na.account_id
How can I fix this query to work? I want to update the field called pdm_id to set it equal to cp.person_id
Thanks
UPDATE accounts na
INNER JOIN call_managment_system.accounts a
ON a.account_id = na.account_id
INNER JOIN temp_accounts ta
ON ta.company_code = a.company_code
INNER JOIN contact_personal cp
ON cp.name = ta.FSM
SET na.pdm_id = cp.person_id
WHERE contact_link = 'PDM'
Can someone help me I've got 2 MySQL queries that get unknown column id when I try to run them. I might add that I am converting this database from SQLServer 2005 to MySQL and they run fine in SQL Server 2005.
Here's 1 of them:
SELECT DISTINCT g.id AS `genre`
FROM media_playlist_sequence MPS
INNER JOIN media M ON M.`key` = MPS.media_key
INNER JOIN media_playlists MP ON MP.`key` = MPS.playlist_key
INNER JOIN node_media_playlist NMP ON NMP.playlist_key = MP.`key`
INNER JOIN nodes N ON N.`key` = NMP.node_key
INNER JOIN media_files MF ON MF.media_key = M.`key`
INNER JOIN media_locations ML ON ML.media_file_key = MF.media_file_key
AND ML.node_key = n.`key`
INNER JOIN media_genres MG ON MG.media_key = M.`key`
INNER JOIN genres G ON G.`key` = MG.genre_key
WHERE M.is_ready = 1
AND MP.id = 'Channels'
AND N.id = 'VIC-WIN7'
AND mf.is_quad_image = 0
My guess is that it's a case sensitivity issue. MySQL can be case sensitive by default whereas SQL Server is not.