String Functions – SPACE()

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

The SPACE() function takes a positive integer replication count [C] as input. The function returns a string composed of a single space concatenated [C] times to itself as output.

The example below adds one, two, and three spaces inside the title of a favorite movie of mine.

One thing to always 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 STR() function. This function was heavily used before the FORMAT() function was released in SQL Server 2012.

Related posts

Leave a Comment