String Functions – REPLICATE()


I am going to continue my series of very short articles or tidbits on Transaction SQL string functions. I will exploring the REPLICATE() function today.

The REPLICATE() function takes a pattern string [S] and a integer replication count [C] as input. The function returns a string composed of pattern string [S] concatenated [C] times to itself as output.

The example below replicates a pattern ‘XO’ five times.

One thing to always worry about when using TSQL functions is how will it react with a EMPTY strings or NULL values? Both empty strings and NULL values as input return themselves as output.

Another thing to worry about when using TSQL functions is how will it react with out of range values. In the example below, a negative replication count returns a NULL string.

Next time, I will be exploring the REVERSE() function.

Related posts

Leave a Comment