IN SQLite I wrote :
UPDATE MYTABLE SET MYFIELD = TRIM(MYFIELD);
What to do to have this on SQL Server 2014 ?
The syntax of trim is TRIM([ characters FROM] string) . If you just string without using characters FROM, then it will trim off the spaces on both sides of the string. If you use 'Characters' FROM, then it will look of the specific characters at the starting and end of the string and removes them.
Remarks. By default, the TRIM function removes the space character from both the start and the end of the string. This behavior is equivalent to LTRIM(RTRIM(@string)) .
The TRIM function is used to remove trailing and leading spaces (char(32)) from a string of characters. This was introduced with SQL Server 2017.
To delete the first characters from the field we will use the following query: Syntax: SELECT SUBSTRING(string, 2, length(string));
UPDATE MYTABLE SET MYFIELD = LTRIM(RTRIM(MYFIELD));
However, field type must be varchar() and not text. Otherwise you get "Argument data type text is invalid for argument 1 of rtrim function"
You need functions LTRIM
(to trim from left) and RTRIM
(to trim from right):
UPDATE MYTABLE SET MYFIELD = LTRIM(RTRIM(MYFIELD));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With