When we are using cast with oreplace then the length of the string is changing.
CAST (OREPLACE(<COL>,' ','') AS CHAR(10))
Column value - 'A B'
When i cast this column as char(10) then the length of the string is 10 but when i use oreplace to remove the embedded space and then use cast as char(10) then the length is changing to 2.
Need help as i dont want the length of the string to change and also want to understand why the length is changing even though i am using cast after oreplace
Solved! Go to Solution.
How are you determining that result length is 2 rather than 10?
SELECT CAST('A B' AS CHAR(10)) AS x, LENGTH(x), TYPE(x), CAST (OREPLACE(x,' ','') AS CHAR(10)) AS y, LENGTH(y), TYPE(y)
A B 10 CHAR(10) CHARACTER SET UNICODE AB 10 CHAR(10)