Padding Strings

Posted: August 11, 2010 in SQL Server 2005

You can use the following functions to LEFT or RIGHT pad strings:

-- This example will RIGHT pad the string with '0' until 15 characters are reached
SELECT 'TestString' + REPLICATE('0', 15 - LEN('TestString'));

-- This example will LEFT pad the string with '0' until 15 characters are reached
SELECT REPLICATE('0', 15 - LEN('TestString')) + 'TestString';
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s