Interview Question of the Week #042 – How Does SPACE Function Works in SQL Server?

This question may sound strange but I have personally observed this being asked in one of the interview.

Question: How Does SPACE Function Works in SQL Server?

Answer: SPACE function accepts one numeric parameter and generates as many as space as a value of the parameter.

Observe the output of the following query:

USE AdventureWorks2014;
GO
SELECT RTRIM(LastName) + ',' + SPACE(5) + ',' + LTRIM(FirstName)
FROM Person.Person
ORDER BY LastName, FirstName;
GO

You will notice there is gap of five space between two commas.

Interview Question of the Week #042 - How Does SPACE Function Works in SQL Server? spacefunction

Reference: Pinal Dave (https://blog.sqlauthority.com)

Previous Post
SQL SERVER – Simple Way to Find Existence of Column in a Table
Next Post
SQL SERVER – Taking Backup Without Consuming Disk Space

Related Posts

No results found.

Leave a Reply