Sql Server Space Function

SQL Server: SPACE Function

In this post explains how to use the SPACE function in SQL Server (Transact-SQL) with syntax and examples.

Description

In SQL Server (Transact-SQL), the SPACE function returns a string with a specified number of spaces.

Syntax

The syntax for the SPACE function in SQL Server (Transact-SQL) is:

SPACE( number )

Parameters or Arguments

number

The number of spaces to be returned.

Applies To

The SPACE function can be used in the following versions of SQL Server (Transact-SQL):

  • SQL Server 2017, SQL Server 2016, SQL Server 2014, SQL Server 2012, SQL Server 2008 R2, SQL Server 2008, SQL Server 2005

Example

Let's look at some SQL Server SPACE function examples and explore how to use the SPACE function in SQL Server (Transact-SQL).

For example:

SELECT SPACE(3);
Output: '   '

SELECT SPACE(7);
Output: '       '

SELECT SPACE(1);
Output: ' '