February 18, 2008

Repeat group of characters 'n' number of times




You can use the rich in-built function set of SQL Server 2005 to perform a variety of tasks. Let us explore how to repeat a group of characters 'n' number of times and also insert space in between two strings.

Repeat a group of characters 'n' number of times

Use the REPLICATE() function to repeat a character expression for a specified number of times

SELECT REPLICATE('-',15) as Underline
displays: the character '-' 15 times ---------------

Insert space in between two strings

SPACE() function returns a string of repeated spaces depending on the number specified

SELECT 'Far' + SPACE(10) + 'Away'
displays: 'Far         Away'


Did you like this post?
kick it on DotNetKicks.com
subscribe via rss subscribe via e-mail
print this post follow me on twitter


About The Author

Suprotim Agarwal, ASP.NET Architecture MVP works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He has also written an EBook 51 Recipes using jQuery with ASP.NET Controls.

Follow him on twitter @suprotimagarwal

 
  Feedback:

comments

2 Responses to "Repeat group of characters 'n' number of times"
  1. danh said...
    November 11, 2009 at 11:57 PM

    I don't think that your SPACE() display string looks right...

  2. Suprotim Agarwal said...
    November 12, 2009 at 12:24 AM

    Thanks Fixed!

 

Copyright © 2009-2014 All Rights Reserved for SQLServerCurry.com by Suprotim Agarwal | Terms and Conditions