Ócáid
Mar 31, 11 PM - Apr 2, 11 PM
An ócáid foghlama SQL, Fabric and Power BI is mó. Márta 31 – 2 Aibreán. Bain úsáid as cód FABINSIDER chun $ 400 a shábháil.
Cláraigh inniuNí thacaítear leis an mbrabhsálaí seo a thuilleadh.
Uasghrádú go Microsoft Edge chun leas a bhaint as na gnéithe is déanaí, nuashonruithe slándála, agus tacaíocht theicniúil.
Applies to:
SQL Server 2017 (14.x) and later
Azure SQL Database
Azure SQL Managed Instance
Azure Synapse Analytics
SQL analytics endpoint in Microsoft Fabric
Warehouse in Microsoft Fabric
Removes the space character char(32)
or other specified characters from the start and end of a string.
Optionally removes the space character char(32)
or other specified characters from the start, end, or both sides of a string.
Starting with SQL Server 2022 (16.x), optionally removes the space character char(32)
or other specified characters from the start, end, or both sides of a string.
Transact-SQL syntax conventions
Syntax for SQL Server 2022 (16.x) and earlier versions, Azure SQL Database, and Azure Synapse Analytics:
TRIM ( [ characters FROM ] string )
Syntax for SQL Server 2022 (16.x) and later versions, Azure SQL Managed Instance, and Microsoft Fabric:
Tábhachtach
You need your database compatibility level set to 160
to use the LEADING
, TRAILING
, or BOTH
keywords.
TRIM ( [ LEADING | TRAILING | BOTH ] [characters FROM ] string )
Applies to: SQL Server 2022 (16.x) and later versions, Azure SQL Managed Instance, and Microsoft Fabric:
The optional first argument specifies which side of the string to trim:
LEADING
removes characters specified from the start of a string.
TRAILING
removes characters specified from the end of a string.
BOTH
(default positional behavior) removes characters specified from the start and end of a string.
A literal, variable, or function call of any non-LOB character type (nvarchar, varchar, nchar, or char) containing characters that should be removed. nvarchar(max) and varchar(max) types aren't allowed.
An expression of any character type (nvarchar, varchar, nchar, or char) where characters should be removed.
Returns a character expression with a type of string argument where the space character char(32)
or other specified characters are removed from both sides. Returns NULL
if input string is NULL
.
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))
.
To enable the optional LEADING
, TRAILING
, or BOTH
positional arguments in SQL Server 2022 (16.x), you must enable database compatibility level 160
on the database that you're connecting to when executing queries.
LEADING
positional argument, the behavior is equivalent to LTRIM(@string, characters)
.TRAILING
positional argument, the behavior is equivalent to RTRIM(@string, characters)
.The following example removes spaces from before and after the word test
.
SELECT TRIM( ' test ') AS Result;
Here's the result set.
test
The following example provides a list of possible characters to remove from a string.
SELECT TRIM( '.,! ' FROM ' # test .') AS Result;
Here's the result set.
# test
In this example, only the trailing period and spaces from before #
and after the word test
were removed. The other characters were ignored because they didn't exist in the string.
Tábhachtach
You need your database compatibility level set to 160
to use the LEADING
, TRAILING
, or BOTH
keywords.
The following example removes the leading .
from the start of the string before the word test
.
SELECT TRIM(LEADING '.,! ' FROM ' .# test .') AS Result;
Here's the result set.
# test .
Tábhachtach
You need your database compatibility level set to 160
to use the LEADING
, TRAILING
, or BOTH
keywords.
The following example removes the trailing .
from the end of the string after the word test
.
SELECT TRIM(TRAILING '.,! ' FROM ' .# test .') AS Result;
Here's the result set.
.# test
Tábhachtach
You need your database compatibility level set to 160
to use the LEADING
, TRAILING
, or BOTH
keywords.
The following example removes the characters 123
from the beginning and end of the string 123abc123
.
SELECT TRIM(BOTH '123' FROM '123abc123') AS Result;
Here's the result set.
abc
Ócáid
Mar 31, 11 PM - Apr 2, 11 PM
An ócáid foghlama SQL, Fabric and Power BI is mó. Márta 31 – 2 Aibreán. Bain úsáid as cód FABINSIDER chun $ 400 a shábháil.
Cláraigh inniu