Data Loader

SPACE function in MS SQL and MySQL

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

MSSQL

Syntax

space(integer)

Example

The following query concatenates FIRSTNAME and LASTNAME from table EMPLOYEES with two spaces in between. Note we are using SPACE function to put two blank spaces in between.

select firstname+space(2)+LastName from employees 
MSSQL SPACE Function Example

MySQL

In MySQL also SPACE function can be used to generate a string of blank spaces.

It's syntax is also similar to MSSQL.

Syntax

SPACE(n) 

Where n is the number of blank spaces required

Example

The following query concatenates FIRSTNAME and LASTNAME from table EMPLOYEES with two spaces in between. Note we are using SPACE function to put two blank spaces in between.

mysql> select concat(firstname,space(2),lastname) from employees;
+-----------------------------------------------+
| concat(firstname,space(2),lastname) 		|
+-----------------------------------------------+
| Nancy Davolio 				|
| Andrew Smythe 				|
| Janet Leverling				|
| Margaret Peacock 				|
| Steven Buchanan				|
| Michael Smith 				|
| Robert King 					|
| Laura Callahan 				|
| Anne Dodsworth 				|
| Nancy Davolio 				|
| Andrew Smythe 				|
| Janet Leverling 				|
| Margaret Peacock 				|
| Steven Buchanan 				|
| Michael Smith 				|
| Robert King 					|
| Laura Callahan 				|
| Anne Dodsworth 				|
+-----------------------------------------------+
SPACE function in MySQL 

Back to Converting Functions from MSSQL to MySQL