Total Pageviews

SQL Server : Replicate ()


While working I was looking for a function which can help me to repeat a particular ‘string’ up to ‘n’ number of times and I can dynamically provide the value of ‘n’ and ‘string expression’ to that function as well.

Replicate() fulfills both requirement.

Replicate help us to repeat a string N number of times.


  1. Example:-

    SELECT
     REPLICATE ('*',10) Result_Set

    Result_Set
    **********

  2. Example:-

    DECLARE @v VARCHAR(10) = '*'
    DECLARE @v1 INT = 4
    SELECT REPLICATE (@v,@v1) Result_Set
    Result_Set
    ****