Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TRIM is not a recognized built-in function name

For the following code:

DECLARE @ss varchar(60)   SET @ss = 'admin'    select TRIM(@ss) 

I've got an error:

'TRIM' is not a recognized built-in function name

like image 723
sathish Avatar asked Jan 24 '19 06:01

sathish


People also ask

Is trim a SQL function?

SQL Server TRIM() Function The TRIM() function removes the space character OR other specified characters from the start or end of a string. By default, the TRIM() function removes leading and trailing spaces from a string.

What does the trim character function do?

TRIM is a function that takes a character expression and returns that expression with leading and/or trailing pad characters removed. Optional parameters indicate whether leading, or trailing, or both leading and trailing pad characters should be removed, and specify the pad character that is to be removed.

What is the equivalent of trim in SQL Server?

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)) .

How do you do Ltrim and Rtrim in SQL Server?

LTrim() and RTrim() Function in MS AccessIn LTrim() function a string will be pass as a parameter and it will return the string with no leading spaces. 2. RTrim() Function : It works same like LTrim() function but it will remove all trailing spaces from a string.


1 Answers

TRIM is introduced in SQL Server (starting with 2017).

In older version of SQL Server to perform trim you have to use LTRIM and RTRIM like following.

DECLARE @ss varchar(60)   SET @ss = ' admin '    select RTRIM(LTRIM(@ss)) 

If you don't like using LTRIM, RTRIM everywhere, you can create your own custom function like following.

   CREATE FUNCTION dbo.TRIM(@string NVARCHAR(max))     RETURNS NVARCHAR(max)      BEGIN       RETURN LTRIM(RTRIM(@string))      END     GO 
like image 111
PSK Avatar answered Oct 03 '22 06:10

PSK