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

来源:互联网 时间:1970-01-01


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:

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

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

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



相关阅读:
Top