SPACE Function in MS SQL Server and MySQL


The MSSQL SPACE function returns a string of a specified number of space characters. It's also available in MySQL with the same name.

MSSQL

Syntax:

space(integer)

The following query concatenates FIRSTNAME and LASTNAME from the EMPLOYEES table with two spaces in between:

select firstname+space(2)+LastName from employees

MSSQL SPACE Function Example

MySQL

In MySQL, SPACE can also be used to generate a string of blank spaces, with similar syntax.

Syntax:

SPACE(n)

Where n is the number of blank spaces required. Example:

mysql> select concat(firstname,space(2),lastname) from employees;
+----------------------------------------+
| concat(firstname,space(2),lastname)    |
+----------------------------------------+
| Nancy Davolio                          |
| Andrew Smythe                          |
| Janet Leverling                        |
| Margaret Peacock                       |
| Steven Buchanan                        |
+----------------------------------------+

SPACE function in MySQL

Back to Converting Functions from MSSQL to MySQL