Logo 
Search:

SQL Server Articles

Submit Article
Home » Articles » SQL Server » String FunctionsRSS Feeds

REPLICATE Function

Posted By: Sarita Patel     Category: SQL Server     Views: 15669

This article explains REPLICATE function of sql server with examples.

REPLICATE is used to repeat a string with specified number of times. 


Syntax of REPLICATE Function :

REPLICATE ( character_expression ,integer_expression )

character_expression is a string to repeat. 

integer_expression is number of times the character_expression to be repeated.

Return type of REPLICATE function is varchar data type.  



Examples of REPLICATE Function :

Example 1 : Use of REPLICATE function in select clause

SELECT REPLICATE('Syntax-Example', 3) 

Output
Syntax-ExampleSyntax-ExampleSyntax-Example

Above example returns repeated string 3 times by specified string.


Example 2 : Use of REPLICATE function to display field value of table in a select clause

SELECT ContactName, REPLICATE(ContactName,2) 'Repeated Name' 
FROM    Customers

Output
ContactName             Repeated Name
Maria Anders             Maria AndersMaria Anders
Ana Trujillo               Ana TrujilloAna Trujillo
Antonio Moreno        Antonio MorenoAntonio Moreno
Thomas Hardy          Thomas HardyThomas Hardy
Christina Berglund     Christina BerglundChristina Berglund
Hanna Moos              Hanna MoosHanna Moos

Above example repeats customers name 2 times from customers table.
  
Share: 

 
 
 

Didn't find what you were looking for? Find more on REPLICATE Function Or get search suggestion and latest updates.

Sarita Patel
Sarita Patel author of REPLICATE Function is from United States.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!