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.
1 2 |
-- A string of XO's select replicate('XO', 5) as str_love; |
1 2 3 4 5 |
output: str_love --------- XOXOXOXOXO |
One thing to always worry about when using TSQL functions is how will it react with a EMPTY strings or NULL…