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?
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.
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.
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)) .
//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
declare @s varchar(25) set @s = ' Amru ' select RTRIM(LTRIM(@s))
You can use this way also without schema :)
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