dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: SQL
Expertise: Beginner
Nov 15, 2005

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


Constructing Strings of Repeated Characters in T-SQL

Sometimes you need to display a string of characters of a specified length for a column value in a SQL query. To this end, SQL Server supports a function called Replicate() which takes two parameters: the character you want to print and the count (the number of times you want to print the character). The first parameter is the character you want to print and the second is the count up to which you need to print the character.

For example, suppose you need to print an asterisk character ('*') some number of times based on a value contained in a Quantity column. Here's how you can do that:


SELECT Quantity, REPLICATE( '*', Quantity)
FROM [Order Details]
WHERE Discount IS NOT NULL

12	************
10	**********
Srinath MS
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date