SPACE function in SQL Server

The SPACE function in SQL Server is used to return a string with the number of spaces specified in the statement.

The article will explore and show you how to use the SPACE function to create a full-space string in SQL Server.

Describe

The SPACE function in SQL Server is used to return a string with the number of spaces specified in the statement.

Syntax

To use SPACE in SQL Server, we use the following syntax:

 SPACE(so_luong) 

Parameters :

  1. so_luong: a positive integer that specifies the number of spaces. If so_luong is negative, the function returns NULL.

Note :

  1. SPACE can be used in later versions of SQL Server: SQL Server 2017, SQL Server 2016, SQL Server 2014, SQL Server 2012, SQL Server 2008 R2, SQL Server 2008, and SQL Server 2005.

For example

Take a look and explore some examples of SPACE functions in SQL Server.

 SELECT SPACE(3); 
Result: ' '

SELECT SPACE(7);
Result: ' '

SELECT SPACE(1);
Result: ' '

Previous article: RTRIM function in SQL Server

Next lesson: STR function in SQL Server

3.5 ★ | 2 Vote