SPACE

Returns a string of spaces. The number of spaces is specified by the integer argument.

SPACE ( integer_expression )

Arguments

integer_expression
Is a positive integer that specifies the number of spaces to be returned. If integer_expression is negative or zero, an empty string is returned.

Return Type

VARCHAR or NVARCHAR

Permissions

No special permissions are required. Any user can execute SPACE.

Examples

A. Returning a specified number of spaces

The following example returns five spaces:

SELECT SPACE(5);

Result:

     
B. Concatenating spaces with other strings

The following example returns the string 'Test' followed by three spaces:

SELECT 'Test' + SPACE(3) + 'String';

Result:

Test   String
C. Using SPACE with table data

This example demonstrates how SPACE can be used to format output by adding spaces between columns from a table.

SELECT
    ProductName,
    SPACE(10) AS Padding,
    ListPrice
FROM Production.Product
WHERE ProductID < 5;

Sample result (actual output will vary based on table data):

ProductName Padding ListPrice
Adjustable Race 0.00
Bearing Ball 0.00
BB Ball Bearing 0.00
Headset Ball Bearings 0.00

See Also