Monday, March 11, 2013

SPACE Function in SQL Server

In this post , I will explain the SPACE function of SQL Server of string functions category.
In my previous posts, I explained SUBSTRING, UPPER, STUFF, LEN and other string functions of  SQL Server. You can also find some other articles related to SQL Server.

Here, I am going to explain SPACE function of SQL Server.

SPACE() Function

This function returns a string of repeated spaces.
 
Syntax- SPACE(integer_expression)
Arguments-
  • integer_expression : An expression of positive integer value which indicates number of spaces. If integer_expression is negative, a null string is returned.
Return Type- char


Example-
 
Declare @nstring int
set @nstring=2
select 'Dot'+Space(@nstring)+'Net'+Space(@nstring)+'World'
--OutPut Dot  Net  World

Declare @nstring int
set @nstring=5
select 'Dot'+Space(@nstring)+'Net'+Space(@nstring)+'World'
--OutPut Dot     Net     World 


No comments:

Post a Comment

^ Scroll to Top