AlphaPress Publishing
P.O. Box 5942 Albany, NY 12205
Tel: 518-250-3890
Email: alphapress@hotmail.com  


  
Click to buy this book from Amazon

Section Menu 

News

Pindaro is now working on a comprehensive book on SQL Server 2014.  For any comments you can email the author at alphapress@hotmail.com.

  

 

 

Use the space() function to insert any number of spaces before or after a field

To contact the author click here

This article is from the book "Access 2007 Pure SQL

To download the sample database click here


 

Use the space() function to insert any number of spaces dynamically before or after a field

Insert ten blank spaces in the beginning and end of the product name field

Discussion:

In some cases, we might want to add any number of blank spaces in the beginning or at the end of the same field.  Using concatenation characters to achieve this task will be a very messy affair.  Instead, we can use the space() function to achieve the same outcome as we do in the example below: 

Code:

SELECT productid,  (space(10)+ productname + space(10))  AS SpacedName, sku

FROM Products

 

Result: