Blog Post

SPACE

,

USE CASE: When we are working on TSQL or some text based scripting we may need some extra space in between two string, we can add space without space function as well but it is possible we may miss to put space in between string or text. If we have to maintain fixed length of space in between string every time we can use TSQL SPACE function.


SPACE

Returns a string of repeated spaces.

SYNTAX

SPACE ( integer_expression ) 

ARGUMENTS

integer_expression
Is a positive integer that indicates the number of spaces. If integer_expression is negative, a null string is returned.

REMARKS

To include spaces in Unicode data, or to return more than 8000 character spaces, use REPLICATE instead of SPACE.

EXAMPLE:-

/*

Considering employee table has three rows;

ID

FIRSTNAME

LASTNAME

1

PRIYA

KUMARI

2

AYUSH

KUMAR

3

RICHA

SINGH

*/

SELECT FirstName +’,’+SPACE(3)+LastName from employee;

PRIYA   KUMARI

AYUSH   KUMAR

RICHA   SINGH

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating