Repeats a string value a specified number of times.
Parameters:
bigint
. If negative, null
is returned. If 0, an empty string is returned.SELECT REPLICATE('a', -1) -- Returns NULL
SELECT REPLICATE('a', 0) -- Returns ''
SELECT REPLICATE('a', 5) -- Returns 'aaaaa'
SELECT REPLICATE('Abc', 3) -- Returns 'AbcAbcAbc'
Note: If string expression is not of type varchar(max)
or nvarchar(max)
, the return value will not exceed 8000 chars. Replicate will stop before adding the string that will cause the return value to exceed that limit:
SELECT LEN(REPLICATE('a b c d e f g h i j k l', 350)) -- Returns 7981
SELECT LEN(REPLICATE(cast('a b c d e f g h i j k l' as varchar(max)), 350)) -- Returns 8050