I'm trying to remove white spaces from a string in SQL but LTRIM
and RTRIM
functions don't seem to work?
Column:
[ProductAlternateKey] [nvarchar](25) COLLATE Latin1_General_CS_AS NULL
Query:
select REPLACE(ProductAlternateKey, ' ', '@'),
LEN(ProductAlternateKey),
LTRIM(RTRIM(ProductAlternateKey)) AS LRTrim,
LEN(LTRIM(RTRIM(ProductAlternateKey))) AS LRLen,
ASCII(RIGHT(ProductAlternateKey, 1)) AS ASCIIR,
ASCII(LEFT(ProductAlternateKey, 1)) AS ASCIIL,
ProductAlternateKey
from DimProducts
where ProductAlternateKey like '46783815%'
Result:
| COLUMN_0 | COLUMN_1 | LRTrim | LRLen | ASCIIR | ASCIIL | PRODUCTALTERNATEKEY |
---------------------------------------------------------------------------------
| 46783815 | 8 | 46783815| 8| 53 | 52 | 46783815 |
| 46783815 | 10|46783815 | 10| 10 | 52 | 46783815 |
Can it be other symbols if LTRIM
and RTRIM
are not working, like "Enter"?
46783815@@
, this gonna work always? no matter how many ASCII characters are in string? – Wyndham