Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have created simple function

create function TRIM(@data varchar(20)) returns varchar(100) as begin   declare @str varchar(20)   set @str = rtrim(ltrim(@data))   return @str end 

I am executing in the below way.

declare @s varchar(25) set @s = '      Amru    ' select TRIM(@s) 

I am getting the following error.

Msg 195, Level 15, State 10, Line 3 'TRIM' is not a recognized built-in function name. 

Could any one please help me find the issue?

like image 946
Shine Avatar asked Jul 25 '11 10:07

Shine


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. Note: Also look at the LTRIM() and RTRIM() functions.

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?

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


2 Answers

//use RTrim instead of Trim sql 2008 

RTrim(ColumnName)

like this

select RTrim(a.ContactName) + ' ' + RTrim(a.City) as Name_City from customers as a 
like image 158
Faraz Ali Siddiqui Avatar answered Oct 04 '22 00:10

Faraz Ali Siddiqui


declare @s varchar(25) set @s = '      Amru    ' select RTRIM(LTRIM(@s))   

You can use this way also without schema :)

like image 25
Nayanajith Avatar answered Oct 04 '22 00:10

Nayanajith