Reputation: 4734
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)) <> ''
Upvotes: 3
Views: 4706
Reputation: 44336
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.
Upvotes: 5