Command "TRIM" SQL Server

Asked

Viewed 2,652 times

8

I’m working with Sql Server, and I need to make a trim as a result of a consultation.

I did it this way:

select TRIM(NUMERO)
from ENDERECO

In the Sql Server Management the command is "recognized", staying in the coloring of a valid command, but returned the following error:

'TRIM' is not a recognized built-in Function name.

I managed to solve with the following command:

select RTRIM(LTRIM(NUMERO))
from ENDERECO

But I needed to use two functions that in my view could be solved with only one function, and the command trim, there is some way to "install" it, because the Sql Server Managemente the colore?

  • 1

    What version of SQL Server you are using?

  • Which version of sql server?

1 answer

10


Problem

The command TRIM is only recognized from the 2017 version, so its Sql Server Managemente recognizes you, but if you are connecting to an old version of Sql Server you will need to utilize the RTRIM and the LTRIM.

Source

Solution

Versions above the 2017

Running the command in versions above 2017

SELECT TRIM('     test    ') AS Result;

Versions below the 2017

Running the command in versions below 2017

SELECT RTRIM(LTRIM('     test    ')) AS Result;

Completion

Certainly it became easier to perform this action in the newest version, using only one function the problem is solved.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.