How could I be sure on the length that I need to use (in CAST) to convert these values to Varchar.
Lookup the use data size per data type and you know the length for the VARCHAR type, see
https://learn.microsoft.com/en-us/sql/t-sql/data-types/data-types-transact-sql?view=sql-server-ver16