简体   繁体   中英

Is there a difference in performance between LTRIM(RTRIM(column_name)) and RTRIM(LTRIM(column_name))

When trimming both ends of a string in SQL Server, is there a performance difference, or any other reason to prefer nesting the LTRIM versus the RTRIM function when building a where clause?

For example:

WHERE RTRIM(LTRIM(SalesPerson)) <> ''

Your query can be replaced with:

WHERE SalesPerson <> ''

Even when there are spaces in '' the check will give the same result. Trimming in this case gives no meaning, and will probably slow your query, since you are comparing with a calculation on the column.

Reversing Ltrim and Rtrim should give no performance difference.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM