Space Function in SQL Server 2008

In this article I describe Space function in SQL Server 2008.
  • 2386

Introduction

Space function is used to replicate the space spaces in string. Space function can be used with select statement or print statement. For example, to concatenate two strings say 'Management" and "Studio". The output should be like: ManagementStudio. But this format is not correct. So we can put space between "Management" and "Studio" through space function.

Syntax:

SPACE ( integer_expression )

where,

integer_expression: indicates the number of spaces to be given between two strings. Value of integer_expression should be a positive integer. Negative value of integer_expression indicates that, null string will be returned.

Example:

Use space function to get spaces between F_Name and L_Name from table named Employee. Type following code:
select F_Name, L_Name, F_Name + SPACE(5) +L_Name from Employee

Output:

spaceFunction-in-sql.jpg


Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.