Wednesday, 26 December 2018

Space function in SQL Server

Space function is used for the spaces in the string. Space function can be used with the select statement or print statement. For example, to concatenate the first name mid name and last name as a full name then it will return full name without space. See below
   
We can use ‘ ‘ (Space) we will get the space.
  
Here I am using 2 space. If we want 10 spaces, we need to give 10 spaces. It will be a bit tidies task. In this case, we will use Space function.
The syntax of Space function as below

SPACE (number of spaces)

See above highlight row we are getting the full name as Null. All we know if we add any string or number in null the result will be the null. To avoiding the null value we need to handle null value when we are adding these values.

See the result
 
 

No comments:

Post a Comment

If you have any doubt, please let me know.

Popular Posts