laika222
10/27/2016 - 6:19 PM

Trim takes characters out of a string - this is helpful to take spaces out from the end and beginning of the string. Line 1 shows how to rem

Trim takes characters out of a string - this is helpful to take spaces out from the end and beginning of the string. Line 1 shows how to remove the spaces (or any string) from the end (TRAILING) of the value in the Company column, within the table Orders4. Line 4 shows how to remove the spaces (or any string) from the beginning (LEADING) of the value in the Company column, within the table Orders4. Line 7 shows how to remove the spaces (or any string) from the both the beginning and the end (BOTH) of the value in the Company column, within the table Orders4. Line 11 shows how to trim a specific string (in this case 'ies) from a string in Company column of the Orders4 table. If this substring is present at the end of the string, then it will be trimmed. Otherwise, no trimming will occur (even if the substring is present elsewhere in the string).

SELECT TRIM(TRAILING ' ' FROM Company)   
FROM Orders4;   

SELECT TRIM(LEADING ' ' FROM Company)   
FROM Orders4;   

SELECT TRIM(BOTH ' ' FROM Company)   
FROM Orders4;  


SELECT TRIM(TRAILING 'ies' FROM Company)   
FROM Orders4;