Skip to content
Advertisement

I am struggling to remove the last 30 characters from data in a column

I am looking to remove the last 30 characters from a colum within my database.

Column Name = gatewayid
Table Name = tblclients

I have created the below which works in the sense it shows me the result and it’s correct but it does not commit or change anything.

SELECT gatewayid, /* ANSI Syntax */SUBSTRING( gatewayid
FROM 1 
FOR CHAR_LENGTH( gatewayid ) -30 ) AS col_trimmed, /* MySQL Syntax */SUBSTRING( gatewayid, 1, CHAR_LENGTH( gatewayid ) -30 ) AS col_trimmed
FROM tblclients

What am I missing, I am a noob 🙂

I expect the data in the column to remove the last 30 characters from each row.

Advertisement

Answer

You need to use update statement:

update tblclients 
set gatewayid = substring( gatewayid, 1, char_length( gatewayid ) -30 );
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement