Table of Contents

    How to Use the SPACE() Function in SQL Server: A Comprehensive Guide

    How to Use the SPACE() Function in SQL Server: A Comprehensive Guide

    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