• Just curious, why are you casting your input to a decimal and then to VARCHAR?

    If you're trying to convert a numerical data type to a SSN or tax ID, try the following:

    RIGHT('000000000' + RTRIM(CAST(Tax_id_number AS VARCHAR)), 9)