currently I have a database with the following parameters and entry:
Now I want to fill the column status_from in this particular entry with the id 1 with a substring of the action column. Which is basically I want to fill my status_from column with a word that comes after from and before to of the action column. To achieve this I've tried using the following statement:
INSERT INTO crm_logs2(status_from) SELECT status_from WHERE id='1' VALUES (substring_index(substring_index(action, 'from', -1),'to', 1))
But doing this gave me the following error:
#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 'VALUES (substring_index(substring_index(action, 'from', -1),
...' at line 1
First, welcome to the SQL Server forum... next, you posted this in the wrong section. You are not running SQL Server 2019, you are running MariaDB.
I would recommend looking up the syntax for MariaDB as I expect you have something wrong in it. Looking at your query, it is definitely not a valid TSQL query. I am not even sure what that is doing at the "VALUES" part... you are inserting into the table crm_logs2, column status_from, then selecting that column where id = '1'. I don't see what that "VALUES" is doing.
As a WILD guess (as I don't have MariaDB installed or know anything about the syntax), I would guess your query should be something more like:
INSERT INTO crm_logs2(status_from, action)
SELECT status_from,
(substring_index(substring_index(action, 'from', -1),'to', 1)) AS action
WHERE id='1'
The above is all just my opinion on what you should do.
As with all advice you find on a random internet forum - you shouldn't blindly follow it. Always test on a test server to see if there is negative side effects before making changes to live!
I recommend you NEVER run "random code" you found online on any system you care about UNLESS you understand and can verify the code OR you don't care if the code trashes your system.
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply