Skip to content
Advertisement

How to add characters in the results up to certain length in SQL

I need to add * symbols to make all records to 15 digits. What is the best way?

Thanks,

Advertisement

Answer

Your other questions are tagged for SQL Server, so I will assume that database.

SQL Server does not support rpad(), but you can use left() and replicate():

or:

If col is not already a string, then you need to cast it to one.

Some databases have direct support for an rpad() function that does this directly.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement