Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (20.3k points)

As compared to say:

REPLICATE(@padchar, @len - LEN(@str)) + @str

1 Answer

0 votes
by (40.7k points)

It's most recommendable to avoid padding varchar on the left to a certain length. Because it's an inefficient use of SQL.

According to me, you need the padding because you are dealing with a fixed length. Have a look at the given query. 

Query:

right('XXXXXXXXXXXX'+ rtrim(@str), @n)

Here, X is the padding character and @n is the number of characters in the resulting string.

Browse Categories

...