SQL Server Articles

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


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

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) 


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

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.


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].

Raj Kumar from India Comment on: Dec 26
i want replicate of x after replicate 321 should be added
only by performing by replicate function only......thankq

View All Comments