SPACE() Function in SQL Server

Rumman Ansari   Software Engineer   2023-03-25   5508 Share
☰ Table of Contents

Table of Content:


Syntax:


SPACE(Number_Of_Spaces) 

Returns number of spaces, specified by the Number_Of_Spaces argument.

Example: The SPACE(5) function, inserts 5 spaces between FirstName and LastName

Code:


Select FirstName + SPACE(5) + LastName as FullName
From TableEmployee

Code: The SPACE(5) function, inserts 5 spaces between FirstName and LastName

Space function in sql server
 
Select FirstName + SPACE(5) + LastName as FullName
From TableEmployee

Prerequisite Code:


CREATE TABLE TableEmployee(
	FirstName varchar(50),
	LastName varchar(50),
	Email varchar(50)
)

INSERT INTO TableEmployee VALUES('Rambo', 'Azmi', 'Rambo@aaa.com')
INSERT INTO TableEmployee VALUES('Azam', 'Ali', 'Azam@aaa.com')
INSERT INTO TableEmployee VALUES('Inza', 'Hoque', 'Rambo@aaa.com')
INSERT INTO TableEmployee VALUES('Jaman', 'Sk', 'Jaman@aaa.com')
INSERT INTO TableEmployee VALUES('Samser', 'Alam', 'Samser@aaa.com')

SELECT * FROM TableEmployee