Hi @Fred Leclere ,
Welcome to the microsoft TSQL Q&A forum!
In SQL you declare a text value by telling the system how much space to reserve for it.
Char(40) allocates 40 bytes for every row.
Varchar(40) uses and offset plus the data, and each row takes up only the space it needs.
As Yitzhak Khabinsky said, You are using a column with CHAR(40) data type. It means there are always 40 characters with trailing spaces regardless of the stored value.
Therefore, if you do not use RTRIM and LTRIM, you cannot automatically remove spaces.
It is a good choice to use RTRIM and LTRIM in the view or cte.
Regards,
Echo
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.