Pages

Wednesday, August 21, 2013

SPACE Function in 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)+'Stores'
    --OutPut Dot  Net  Stores

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

    No comments:

    Post a Comment