Caché SQL Reference
SPACE
[Home] [Back] [Next]
InterSystems: The power behind what matters   
Class Reference   
Search:    

A string function that returns a string of spaces.
Synopsis
SPACE(count)
{fn SPACE(count)}
Arguments
count An integer expression specifying the number of blank spaces to return.
Description
SPACE returns a string of blank spaces count spaces long. If count is a numeric string, a decimal number, or a mixed numeric string, Caché resolves it to its integer portion. If count is a negative number or a nonnumeric string, Caché resolves it to 0.
To remove blank spaces from a string, use LTRIM (leading blanks) or RTRIM (trailing blanks).
Note:
The SPACE function should not be confused with the SPACE collation type. SPACE collation appends a single space to a value, forcing it to be evaluated as a string. To establish SPACE collation, CREATE TABLE provides a %SPACE collation keyword, and ObjectScript provides the Collation() method of the %SYSTEM.Util class.
Examples
The following embedded SQL example returns a string of spaces the length of the name field:
   &sql(SELECT SPACE(LENGTH(name))
   INTO :a
   FROM Sample.Person)
   IF SQLCODE'=0 {
     WRITE !,"Error code ",SQLCODE }
   ELSE {
     WRITE !,"Leave this much space:",a,"for names" }
 
See Also
LTRIM RTRIM TRIM